Running totals give you the sum of a value + all of the previous values in that column.
Here’s an example of a running total:
And here’s the SQL used in the table calculation:
In general, the SQL used for calculating running totals has two bits (with an optional third bit):
column_I_want_to_sum
- this is the column with the values you want to add upcolumn_I_want_to_order_by
- this is the column you want to order your running total overoptional_other_column_I_want_to_order_by
- this column is optional and you can add as many more order by
columns as you need. For your running total to only go up an increment of one row, you’ll need to add every dimension in your results table to the ORDER BY
bit in your SQL. And, the order of these will need to be the same as the ordering you’ve added to the columns in your results table.💎 Level up your SQL:
ASC
and DESC
in your ORDER BY
clause. By default, a column will be ordered in ascending order - so if you want it ordered ascending, you don’t need to add anything.