What is reports as code?

Reports as code means keeping each recurring report as plain-text files, SQL for the data and YAML for the layout and delivery, in version control. A tool validates, runs and delivers them. It is the same idea that infrastructure as code brought to servers and dbt brought to data transformation, applied to the reports people receive.

The principles

Plain text

A report is SQL for the data and YAML for the shape and the delivery. No GUI, no binary files.

In git

Every change is a commit: reviewed in a pull request, with history, blame and a way back.

Declared, not scripted

You say what the file looks like and where it goes; the tool does the work the same way for every report.

Checked before it runs

The project is validated and its SQL compiled before anything reaches a database or an inbox.

One definition, many environments

The same report runs against dev and prod, and for every client or region, by configuration.

Run by automation

An orchestrator runs it on time; nobody has to remember to send it.

An example

A monthly sales workbook with one tab per query, money formatted, emailed to finance. With DRE it is two files and one command.

reports/sales/sales.sql
select region, count(*) as orders, sum(amount) as net
from {{ source('shop', 'orders') }}
where order_date between '{{ run.date.prev_month.start.date }}'
                     and '{{ run.date.prev_month.end.date }}'
group by region
order by net desc
reports/sales/sales.yml
queries:
  - {query: sales, tab_name: By region}
output:
  format: xlsx
  columns:
    net: {format: "#,##0.00"}
  destination:
    profile: mail
    to: finance@example.com
    subject: "Sales {{ run.date.prev_month.start.date }}"
terminal
dre validate -s sales   # check it, and see where the file will go
dre run sales           # build the workbook and send it

Why teams move to it

  • A wrong number can be traced to the commit that changed it
  • New reports copy a reviewed pattern instead of starting from a blank script
  • Anyone who reads SQL can review a report change
  • Coding agents can write and change reports, because everything is text