# Post daily KPIs from SQL to Slack, with the Excel attached | DRE

> Turn SQL query results into a short headline (revenue, change, top regions) posted to Slack or email, with the Excel workbook attached.

[← All use cases](https://getdre.com/use-cases/)

# A headline in Slack, the workbook attached

Most people who depend on a report never open the file: they want last month’s revenue, the change, the top regions. With a message output, one run of the queries builds the workbook and a short headline, and the headline arrives in Slack with the workbook attached.

[Try it yourself: Conditional Slack headline](https://github.com/get-dre/dre/tree/v0.5.1/examples/slack-headline/)

Recorded from a real run: --preview prints the message, then the run posts it.

Recorded from a real run: --preview prints the message, then the run posts it.

![A Slack post from the DRE bot: the headline in bold, revenue, orders and the top regions, with the Excel workbook attached and previewed](https://getdre.com/media/headline/slack.webp)

The post in Slack (a real screenshot of a test workspace, cropped to the message).

![The same headline as an HTML email in Mailpit, with the workbook attached](https://getdre.com/media/headline/email.webp)

The same headline as an email body, with the workbook attached (Mailpit).

![A Databricks Volume in Catalog Explorer listing the headline .md files](https://getdre.com/media/headline/volume.webp)

Every message is also a .md file, so any file destination delivers it as is: here a Databricks Volume (--set msg\_volume; a real screenshot).

reports/messages/msg\_daily/msg\_daily.yml

```yaml
queries: [msg_headline, msg_regions]
output:
  - name: workbook
    format: xlsx
    queries: [msg_regions]
    destination: {profile: local, path: "out/messages/regions-{{ run.date.yyyymmdd }}.xlsx"}
  - name: headline
    format: message
    title: "{{ var('company') }}: {{ period(var('period')).start.format('%B %Y') }}"
    text: |
      Net revenue: **{{ results.msg_headline.first.net | currency('EUR') }}** ({{ results.msg_headline.first.change | percent | signed }} on the month before)
      Orders: {{ results.msg_headline.first.orders | number }}
      Top regions:
      {% for r in results.msg_regions.rows[:3] %}- {{ r.region_name }}: {{ r.net | currency('EUR') }}
      {% endfor %}
    destination:
      - {profile: slack, attach: [workbook]}
```

reports/messages/msg\_daily/msg\_headline.sql

```sql
{% set p = period(var('period')) %}
{% set before = period('last_month', as_of=p.start.date) %}
select
  sum(net_amount) filter (where order_date between '{{ p.start.date }}' and '{{ p.end.date }}') as net,
  count(distinct order_id) filter (where order_date between '{{ p.start.date }}' and '{{ p.end.date }}') as orders,
  sum(net_amount) filter (where order_date between '{{ p.start.date }}' and '{{ p.end.date }}')
    / nullif(sum(net_amount) filter (where order_date between '{{ before.start.date }}' and '{{ before.end.date }}'), 0) - 1 as change
from {{ ref('paid_order_facts') }}
```

terminal

```bash
dre run msg_daily --preview   # print the message, send nothing
dre run msg_daily
```

### What to notice

-   The queries run once: the workbook and the headline can never disagree.
-   queries: on each output keeps the one-row headline query out of the workbook.
-   Number filters (currency, percent, signed, number) follow the project’s locale.
-   Slack gets the headline with the workbook attached; email puts it in the body. Microsoft Teams and Google Chat (in preview) take the message only.

### In the docs

-   [Messages →](https://getdre.com/docs/messages/)
-   [The slack destination →](https://getdre.com/docs/plugin-slack/)

## More use cases

[

### Trustworthy AI with MCP

Reviewed report answers, local refinements and documented table exploration, with clear provenance.

](https://getdre.com/use-cases/trustworthy-ai-with-mcp/)[

### Monthly finance pack

A multi-sheet Excel workbook with money formats, formulas, totals and a branded template.

](https://getdre.com/use-cases/monthly-finance-pack/)[

### A file for a bank or regulator

Fixed-width or delimited files to the exact layout the other side asks for, dropped on SFTP.

](https://getdre.com/use-cases/file-for-a-bank/)
