Table calculation SQL templates
Percent of previous value
Here’s an example of a percent of previous value calculation:
And here’s the SQL that was used to generate it:
In general, the SQL used for calculating the percent of the previous value has two bits (with an optional third bit):
column_I_want_to_compare
- this is the column with the values you want to comparecolumn_I_want_to_order_by
- this is the column you want to use to order the values you want to compareoptional_other_column_I_want_to_order_by
- this column is optional and you can add as many moreorder by
columns as you need. Normally, you’ll need to add every dimension in your results table to theORDER 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.
Here’s the SQL you can copy-paste to calculate the percent of the previous value
Make sure to add percent formatting to your calculation
In the format
tab, make sure to update the format to percent
so that your table calculation is shown as a percentage value (instead of a number).