Data Lake • Write your own SQL
Compare over time
Is it up or down since last month, and what is the total so far?
Try this
Run this on my data lake and show all rows: SELECT month, revenue, SUM(revenue) OVER (ORDER BY month) AS running_total, revenue - LAG(revenue) OVER (ORDER BY month) AS change FROM ( SELECT date_trunc('month', order_date) AS month, SUM(amount) AS revenue FROM samples.shop_orders WHERE order_date >= DATE '2026-01-01' GROUP BY 1 ) t ORDER BY month
In plain words
What is it?
Each month gets two extra numbers: the change from the month before, and everything added up so far.
How does it work?
LAG looks one row back. SUM with OVER adds up every row down to the current one.
Good to know
Ask for all rows, or you only see the first 10 months. The newest month may not be finished.
Then try
Plain monthly totals
Run this on my data lake and show all rows: SELECT date_trunc('month', order_date) AS month, SUM(amount) AS revenue FROM samples.shop_orders GROUP BY 1 ORDER BY 1