Advanced Chart Calculations: Nested Calculations
A nested calculation computes a measure over internal dimensions that only that measure uses, independently of the chart’s dimensions, and then aggregates the result to the chart’s rows. Uses include average monthly revenue per country in a chart without a month dimension, the stickiness rate of a product, and correlations.
Nested calculations are one category of advanced chart calculations. For worked examples, see the advanced calculations demo app.
Activating nested calculations
Section titled “Activating nested calculations”In the Data tab of the chart’s properties panel, expand the measure and choose a type from the Nested drop-down, then fill in the settings for that type.
Nested calculation types
Section titled “Nested calculation types”| Type | Returns |
|---|---|
| Nested calculation | The measure calculated for each combination of the additional dimensions, then aggregated. For example, the average number of unique active users per day over the last 30 days. |
| Nested ratio | The measure aggregated at one internal grain, divided by the measure aggregated at another. For example, average daily active users divided by monthly active users. |
| Nested correlation | The correlation coefficient between two dimensions for one measure, or between two measures. |
| UDF | The result of a user-defined function from your database, applied to the measure’s values. |
Nested calculation
Section titled “Nested calculation”Adds dimensions for this measure only. For example, a table of revenue by country and occupation can show the average monthly revenue of each row without a month dimension.
- Aggregation: how the internal results are combined for each chart row: Sum, Min, Max, Avg or Percentile. For Percentile, see Percentile settings.
- Additional dimensions: the internal dimensions the measure is calculated for.
- Output type: what the calculation returns.
-
Default: the aggregated value.
-
Dimension value: instead of a number, the value of the internal dimension at the record that Position picks, for example the month in which the measure is lowest (Bottom).

-
Value in a series: a value from the first or last record of the internal series, chosen in Position, transformed by Function: Percent rank returns that value’s percent rank in the series, and Standard score returns how many standard deviations it lies from the series mean.

-
With the settings above and Output type set to Default, each row of the country and occupation table shows its average monthly revenue, although the table has no month dimension:
Nested ratio
Section titled “Nested ratio”Divides the measure aggregated over one set of internal dimensions by the measure aggregated over another. For example, the stickiness rate of a SaaS product is average daily active users divided by monthly active users.
- Aggregation: the aggregation of the numerator.
- Bottom Aggregation: the aggregation of the denominator.
- Additional dimensions: the internal dimensions of the numerator.
- Bottom dimensions: the internal dimensions of the denominator.
Nested correlation
Section titled “Nested correlation”Returns a correlation coefficient. Two kinds are supported:
-
Between two dimensions, using one measure, such as a correlation matrix:

-
Between two measures, using one dimension, such as two measures over time:

- Additional Dimension: the dimension that pairs up the values being correlated. It is usually a date, since correlation is usually tested over time.
- Compare measure: the second measure, for a correlation between two measures. Use it only when the chart has one dimension.
A nested correlation can also compare two date ranges; see Date ranges comparison.
User defined function (UDF)
Section titled “User defined function (UDF)”A user-defined function (UDF) applies a function defined in your database to the measure’s values. In a nested calculation, the function must take two inputs, an array of values and a control value (a number or a string), and return a single value.
This Snowflake example calculates a percentile from the exclusive rank q × (n + 1), where n is the number of values. It returns NULL when the rank is less than 1 or at least n. 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';After the function is registered in the semantic layer, it can be chosen in a chart:
- Select UDF: the function to use.
- Additional dimensions: the internal dimensions the measure is calculated for.
- The function’s other input, such as q float in the example: the control value passed to the function.
- Output type: the same options as for a nested calculation.
Period over period without a time dimension
Section titled “Period over period without a time dimension”A period-over-period calculation in a chart without a date dimension, such as year-over-year growth in a KPI, uses nested time dimension mode, which is set on the period-over-period calculation rather than in the Nested drop-down. See Nested time dimension mode.
Semantic layer equivalent
Section titled “Semantic layer equivalent”On a business question in a semantic layer, a measure selection can compute the measure at a finer grain and then aggregate it with Sum, Avg, Min or Max. See Computing a measure at a finer grain, and Calculations over the answer for the calculations that run on the answer’s rows.






