Chart calculations in the classic Workbook Editor
This page covers calculations you set on a chart measure in the classic Workbook Editor: running totals, moving averages, growth against an earlier period, ranks, shares of a total, calculations at a finer grain than the chart shows, and line chart forecasts. To keep a calculation like these as a governed measure that every chart and app reuses, define it in the semantic layer instead, as a time intelligence measure or a calculated measure.
A running total, for example, shows annual recurring revenue building up quarter by quarter:

Add a calculation to a measure
Section titled “Add a calculation to a measure”- Select the chart and open its Data tab. See Set an object up in the properties panel.
- Expand the measure.
- Choose a calculation from one of two drop-downs:
- Advanced calculation for the calculations grouped under Moving Aggregations, Period over Period and Others.
- Nested for a calculation over dimensions the chart does not show. See Nested calculations.
- Fill in the settings that appear below the drop-down. A red icon beside a setting means its value is not valid; hover over it for the reason.
A measure can use both drop-downs. To remove a calculation, choose None.
Where calculations are available
Section titled “Where calculations are available”Most charts show both drop-downs on each measure. If a measure has neither, that measure does not support calculations; in some charts, such as a treemap or a waterfall, only the supporting measures offer them. Some charts offer only part of the list:
- A table shows Advanced calculation only when its type is Table. An Expandable table or a Pivot table offers only Nested. See Tables.
- A KPI has no dimensions, so it offers the nested calculations and the period-over-period Value, Difference, Rate, Growth, Annualized Period Growth and Compound Annual Growth Rate. To compare periods in a KPI, use a nested time dimension.
Moving aggregations
Section titled “Moving aggregations”Moving aggregations combine each record with the records before it, or around it. Their Aggregation can be Sum (the default), Avg, Min or Max.
| Calculation | Returns |
|---|---|
| Running Total | The aggregation of all records up to and including the current one, such as revenue to date. |
| Running Rate | The running total divided by the measure’s total, so the last record reaches 100%. |
| Moving Calculation | The aggregation over a window of records around the current one, such as a moving average. |
Running Total and Running Rate have two more settings:
- Dimensions: the dimensions the calculation restarts for. With none chosen, it restarts for each value of the chart’s second dimension, if the chart has one.
- Order by: the order the records accumulate in, independent of the chart’s sorting.

A running rate shows how fast a total builds up. This chart compares the share of each year’s revenue reached by each month:

Moving Calculation sets its window with two numbers, counted from the current record: negative numbers count records before it and positive numbers count records after it.
- Periods before: the start of the window. The default is -6.
- Periods after: the end of the window. The default is 0, the current record. It cannot be smaller than Periods before.
- Null if there are not enough values: when ticked, records whose window is incomplete, near the start or end of the chart, show no value.
A six-month moving average smooths out seasonality and one-off spikes:

With Aggregation Avg, Periods before -2, Periods after 0 and Null if there are not enough values ticked, each quarter shows the average of itself and the two quarters before it, and the first two quarters are empty:

Period over period
Section titled “Period over period”A period-over-period calculation compares each record with another record along the chart’s dimension. Compare with period sets how far away the comparison record is: -1, the default, is the previous record, and -4 with quarterly data is the same quarter a year earlier. A positive number compares with a later record. It must be a whole number and cannot be 0.
| Calculation | Returns |
|---|---|
| Value | The comparison record’s value, such as the same quarter last year. |
| Difference | current − comparison |
| Rate | current / comparison. Empty when the comparison is 0. |
| Growth | (current − comparison) / |comparison| |
| Correlation | The correlation of period-over-period changes. See Correlations. |
| Accumulated Growth | The growth of the measure’s running total against another measure’s running total. |
| Annualized Period Growth | (current / comparison)n − 1, where n is Number of periods in a year. |
| Compound Annual Growth Rate | (current / comparison)1/n − 1, where n is the number of periods back. |
Growth divides by the absolute value of the comparison, so a rise is always positive, even from a negative value:

Accumulated Growth returns (running total of the measure − running total of the comparison measure) / |running total of the comparison measure|. Add the comparison measure under Compare Measure, which needs at least one dimension in the chart, and set the accumulation order with Order by, as for a running total. Use it, for example, to compare revenue to date this year with revenue to date last year.
Annualized Period Growth scales the growth between two periods to a year, so you can compare quarter-on-quarter or month-on-month growth with year-on-year growth. Set Number of periods in a year, for example 4 for quarters; it must be positive. Compare with period must be negative, and is usually -1: the formula does not adjust for a larger offset, so with quarters and -4 a ratio of 1.1 returns 46.41%, not 10%.
Compound Annual Growth Rate (CAGR) returns the average growth per period over several periods. n is the absolute value of Compare with period, which must be negative. With -2 and a ratio of 1.21, CAGR is 10%.
Compare periods without a date in the chart
Section titled “Compare periods without a date in the chart”To show a period-over-period result in a chart that has no date dimension, such as year-on-year growth in a KPI or for each country in a bar chart, turn on Nested time dimension under the calculation. It is available for Value, Difference, Rate, Growth, Annualized Period Growth and Compound Annual Growth Rate.
The time dimension then comes from a date filter inside the measure’s own definition, so the measure must be a custom calculation that filters a date field in one of two ways:
-
With a predefined period filter, such as current year to date, the comparison steps by that period, and Compare with period sets how many periods back.

-
With a date range filter, for example between two dates viewers can change, choose the step in Time period: Year, Quarter, Month, Week or Day.


Rank, total and compare to total
Section titled “Rank, total and compare to total”The calculations under Others compare each value with the rest of the chart. Each has a Dimensions setting: choose dimensions to rank or total within each of their values, or none to work across all rows.
Rank returns the position of each value.
- Order: Asc, the default, ranks the lowest value first; Desc ranks the highest first.
- Dense: when ticked, tied values share a rank and the next value takes the next rank, so ranks 2, 2, 3. When cleared, the next value skips the ranks the tie used, so ranks 2, 2, 4.

This table ranks revenue across all rows, and again within each country:

Total returns the measure’s total for the chosen dimensions on every row. Aggregation can be Sum, Avg, Min, Max, Percentile (see Percentiles) or Control value, which returns the average plus the number of Standard deviations you enter.

Compare to Total compares each value with that total. Type of comparison sets how:
- Rate, the default: value / total, such as a share of the sum.
- Difference: value − total, such as the difference from the average.
- Growth: (value − total) / |total|, such as the growth over the average.
Its Aggregation can be Sum, Avg, Min, Max, Percentile or Outliers. Outliers always uses Difference: it returns how far a value lies outside the average plus or minus the Standard deviations you enter, which must be more than 0, and 0 for a value inside that band.

This table shows each occupation’s share of its country’s revenue, the country average, and the difference and growth against that average:

To index every value against one point on the chart’s first dimension, turn on Index chart settings. Enter that point in Index Base Value, for example a year or a region, and the scale in Index Scale, which defaults to 100. With Rate, the base point then shows as 100 and every other value relative to it.
Percentiles
Section titled “Percentiles”When Aggregation is Percentile, in Total, Compare to Total or a nested Calculation, three more settings appear:
- Percentile value: the percentile to return, between 0 and 1. 0.5 returns the median.
- Continuous: when off, the result is a value that occurs in the data. When on, it is interpolated between values, so it usually does not occur in the data.
- Approx: when on, the database’s approximate percentile function is used, which is faster on large data but not exact.
Nested calculations
Section titled “Nested calculations”A nested calculation works out the measure over extra dimensions that only this measure uses, then aggregates the result to the chart’s rows. For example, a table of revenue by country and occupation can show each row’s average monthly revenue without a month dimension. Choose the type from the measure’s Nested drop-down:

| Type | Returns |
|---|---|
| Calculation | The measure for each combination of the extra dimensions, then aggregated, such as average daily users. |
| Ratio | The measure aggregated at one grain divided by the measure aggregated at another. |
| Correlation | The correlation between two dimensions for one measure, or between two measures. See Correlations. |
| UDF | The result of a function in your database, applied to the measure’s values. |
Calculation
Section titled “Calculation”-
Aggregation: how the inner results combine for each chart row: Sum, Avg, Min, Max or Percentile (see Percentiles).
-
Additional Dimensions: the dimensions the measure is first calculated for.
-
Output type:
- Default: the aggregated value.
- Dimension value: the value of the additional dimension at the bottom or top result instead of a number, such as the month in which revenue was lowest. Set Position to Bottom or Top.
- Value in a series: the first or last value of the inner series, transformed by Function. Set Position to First or Last. Percent rank returns its percent rank within the series, and Standard score returns how many standard deviations it lies from the series mean. Add the dimensions that order the series under Series Dimensions.


With these settings, each row of the country and occupation table shows its average monthly revenue:

Divides the measure aggregated over one set of dimensions by the measure aggregated over another. For example, the stickiness of a product is average daily active users divided by monthly active users.
- Aggregation and Additional Dimensions: the numerator.
- Bottom Aggregation and Bottom Dimensions: the denominator. Bottom Aggregation can be Sum, Avg, Min or Max.
The ratio returns nothing until both Additional Dimensions and Bottom Dimensions have at least one dimension.

UDF applies a user-defined function from your database to the measure’s values. It appears in the Nested drop-down only when user-defined functions are enabled for your account and at least one function is registered in the semantic layer.
- Select UDF: the function.
- One setting for each of the function’s parameters, labelled with its name and data type. For a parameter that takes the measure’s values as an array, add the dimensions to collect them by under Select Additional Dimension. For any other parameter, enter a value or pick a variable.
- Output type: the same options as for Calculation.

This Snowflake function, used in the example above, takes an array of values and a percentile and
returns one number. It calculates the percentile from the exclusive rank q × (n + 1), where n is
the number of values, and returns NULL when that rank is less than 1 or at least n. Despite its
name, it does not match Excel’s PERCENTILE.INC:
CREATE OR REPLACE FUNCTION DEMO_DATASET.PUBLIC.PERCENTILE_EXCEL("DATA" ARRAY, "Q" FLOAT)RETURNS FLOATLANGUAGE SQLAS ' CASE WHEN ARRAY_SIZE(data) = 0 THEN NULL WHEN q * (ARRAY_SIZE(data) + 1) - 1 < 0 OR FLOOR(q * (ARRAY_SIZE(data) + 1) - 1) >= ARRAY_SIZE(data) - 1 THEN NULL ELSE ARRAY_SORT(data)[FLOOR(q * (ARRAY_SIZE(data) + 1) - 1)::INT] + (ARRAY_SORT(data)[FLOOR(q * (ARRAY_SIZE(data) + 1) - 1)::INT + 1] - ARRAY_SORT(data)[FLOOR(q * (ARRAY_SIZE(data) + 1) - 1)::INT]) * (q * (ARRAY_SIZE(data) + 1) - 1 - FLOOR(q * (ARRAY_SIZE(data) + 1) - 1)) END';Correlations
Section titled “Correlations”Two calculations return a correlation coefficient:
- Period-over-period Correlation, under Advanced calculation, correlates the measure’s period-over-period changes, typically in a heat map or correlation matrix. Add the dimensions to correlate over, usually including a date, under Additional Dimensions, set Compare with period, and choose a Comparison type: Absolute (the difference between the two values), Percentage (the default, the rate of change) or Natural log.
- Nested Correlation correlates two dimensions for one measure, such as a correlation matrix of product categories, or two measures along one dimension. Add the dimension that pairs the values, usually a date, under Additional Dimensions. For two measures, add the second under Compare Measure, which needs at least one dimension in the chart.



Either correlation can compare two date ranges instead of consecutive records. Turn on Ranges comparison, set Start and End under Range and under Comparison Range, and choose a Comparison type: Absolute returns the difference between the two results and Percentage the percentage change. Each date can be fixed or come from a variable, so viewers can change the ranges.

Forecast a line chart
Section titled “Forecast a line chart”A line chart can extend a measure past its last data point. The Forecasting section appears in the line chart’s Data tab only when the chart has exactly one dimension and that dimension is a date, not a date part. While a forecast is on, the chart’s sorting is disabled. A change that breaks these conditions, such as adding a second dimension, removes the chart’s forecasts.
- In Forecasting, add a forecast and pick the measure. You can add more than one.
- Choose the forecast type:
- Linear fits a straight line through the data and continues it. It suits a measure that rises or falls by a roughly constant amount per point.
- Exponential fits a curve and continues it. It suits a measure that grows or shrinks by a roughly constant percentage per point. It cannot fit data with zero or negative values.
- Growth Scenarios (%) grows the last value by a rate you set, instead of following the trend. See Growth scenarios.
- For Linear and Exponential, choose which points to fit: All data, or Custom range to fit only the most recent points, set in Reference Points.
- Set Forecasted points, how many points to add after the last one. The default is 5.
- Optionally, enter a Label, and change the line style, width and color. By default the forecast is a dashed line in a lighter shade of the measure’s color.
Show reference line, on by default, draws a vertical line where the forecast starts. It is set on the first forecast, which also holds its Reference label.


An Exponential forecast curves instead of running straight:

Growth scenarios
Section titled “Growth scenarios”A Growth Scenarios (%) forecast compounds a growth rate from the last data point, such as a plan for 10% growth a year. Enter the rate per period in Expected Growth (default 10%) and set Points per period, how many data points make up one growth period (default 1). For example, $10,000 growing at 10% a year for 3 years becomes $13,310. A point part-way through a period gets the matching share of that period’s compounded growth.
| Each data point is | Points per period |
|---|---|
| One day | 7 for a week, about 30 for a month, about 365 for a year |
| One month | 3 for a quarter, 12 for a year |

For the rest of the line chart’s settings, see Charts.
In the semantic layer
Section titled “In the semantic layer”Business questions offer the same calculations as governed definitions. Running totals, moving calculations, ranks, totals and comparisons with a total or with another row are calculations over the answer. Nested calculations correspond to computing a measure at a finer grain, and period-over-period comparisons without a date in the answer use period axes.