Creating a running total across rows with table calculations

You can create a running total across rows with table calculations using the pivot_offset function.

You can also create a running total down columns with table calcs using the running_total function. Read more about this here.

To create a running total across rows, use the pivot_offset function to add each value to the previous values in that row, while using coalesce() on each previous value to ensure it is not NULL.

For example, if you have this query:

You can write this table calculation:

${order_items.count} + 
coalesce(pivot_offset(${order_items.count},-1),0) +
coalesce(pivot_offset(${order_items.count},-2),0) +
coalesce(pivot_offset(${order_items.count},-3),0)

Giving you these results!

3 15 11.8K
15 REPLIES 15
Top Labels in this Space