← All use cases

KPI cards in Slack, Excel and PDF attached

Put the numbers people need in the channel they read. DRE builds Slack Block Kit cards and charts from query results, with reusable .json components for the layout. The daily KPI demo posts revenue, orders and average order value, a 14-day revenue chart, and Excel and PDF files from the same data.

Try it yourself: Conditional Slack headline

Plain headline example: --preview prints the message, then the real run posts it.

Plain headline example: --preview prints the message, then the real run posts it.

What it produces

Slack Block Kit post with three KPI cards for Revenue, Orders and Avg order value, a 14-day revenue line chart, and daily_kpis.xlsx and daily_kpis.pdf attached
The daily KPI report in Slack: Block Kit cards, a revenue chart and Excel and PDF files posted beneath. Real screenshot; fictional demo data.
A plain headline as an HTML email in Mailpit, with the workbook attached
The plain headline example as an email body, with the workbook attached (Mailpit).
A Databricks Volume in Catalog Explorer listing the headline .md files
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).

How it’s built

The report’s SQL and YAML, as they sit in the project, and the commands that run it. A complete, runnable version is in the public examples (linked above).

reports/messages/daily_kpis/daily_kpis.yml
queries: [daily_kpis_days]
output:
  - name: workbook
    format: xlsx
    queries: [daily_kpis_days]
    destination: {profile: local, path: "out/messages/daily_kpis.xlsx"}
  - name: summary_pdf
    format: pdf
    template: {file: daily_kpis.html}
    destination: {profile: local, path: "out/messages/daily_kpis.pdf"}
  - name: kpis
    format: message
    title: "Daily KPIs"
    text: "Daily KPIs for {{ results.daily_kpis_days.rows[-1].day }}"
    destination:
      - profile: local
        path: "out/messages/daily_kpis.md"
default_set: files
sets:
  - name: files
  - name: slack
    output:
      name: kpis
      destination:
        - profile: slack
          attach: [workbook, summary_pdf]
          files_in: message
          blocks:
            - {type: header, text: {type: plain_text, text: "Daily KPIs · {{ results.daily_kpis_days.rows[-1].day }}"}}
            - component: kpi_cards.json
              with: {query: daily_kpis_days}
            - component: revenue_chart.json
              with: {query: daily_kpis_days}
            - type: context
              elements: [{type: mrkdwn, text: "Sent by DRE · daily_kpis"}]
reports/messages/msg_daily/msg_daily.yml
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
{% 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
dre run msg_daily --preview   # print the message, send nothing
dre run msg_daily