Tomas Lima
06/05/2025, 10:57 PMMoises Morales
06/05/2025, 11:36 PMMichal Hauzírek
06/08/2025, 8:27 AMSELECT RUNMIN(metric) WITHIN (attribute, ALL OTHER) ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING
and it will do what this SQL would do:
SELECT LAG(metric) OVER PARTITION BY attribute ORDER by Date
basically give you a previous (based on the Date) value of the metric and you can use WITHIN to specify the group within which you want the previous value (i.e. previous order of the same customer or of the same product).
This will work when used with a date dimension in a report (or inside another metric with BY Date, ALL OTHER
).
If you ever needed the next value (i.e. SQL function LEAD) just change it to ROWS BETWEEN 1 FOLLOWING and 1 FOLLOWING