Skip to content

Advanced Chart Calculations: Nested Calculations

5 min read · Updated 13 Nov 2026

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.

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 drop-down in the measure settings, listing None, Calculation (selected), Ratio, Correlation and UDF.

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.

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.

Nested calculation settings: Nested set to Calculation, Aggregation Avg, Additional Dimensions Month Year, Output type Default.

  • 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).

      Output type set to Dimension value, with the Position drop-down set to 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.

      Output type set to Value in a series, with Position First and Function Percent rank.

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:

Customer Sales Comparison table of Sales Country and Occupation with an Avg Monthly Revenue column, such as $96,201.3 for Australia Professional.

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.

Line chart titled Nested Ratio showing daily to monthly active users, with the Ratio nested settings in the properties panel.

Nested Ratio settings: Aggregation Avg, Bottom Aggregation Sum, and empty Additional Dimensions and Bottom Dimensions lists.

  • 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.

Returns a correlation coefficient. Two kinds are supported:

  • Between two dimensions, using one measure, such as a correlation matrix:

    Heat map of sales correlation between product subcategories, with percentage values from about 65% to 95% in each cell.

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

    Line chart titled Sales and Gross profit correlation over time, with the correlation swinging between about -93% and 60%.

Nested Correlation settings with Order Date New as the Additional Dimension and an empty Compare Measure section.

  • 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.

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 FLOAT
LANGUAGE SQL
AS '
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:

Nested calculation settings set to UDF, with Select UDF “Percentile Exec”, additional dimension Order Date New, q float 0.95 and Output type Default.

  • 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.

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.