Tableau function Aggregate

Tableau STDEVP to SQL

STDEVP(expression) returns the population standard deviation of the non-null values, dividing by n. In SQL that is stddev_pop(Sales). Watch the name: in DuckDB, Snowflake and BigQuery the unqualified STDDEV is the sample version, not this one.

Updated · Checked on the xmetric engine

What is the syntax?

STDEVP(expression)
expression
a numeric field or row-level calculation.

Returns a real number: the population standard deviation, dividing by n. Null when the group has no values; 0 when it has one.

What does it return, and what is the SQL?

Each example runs on the same 12 sample rows twice: the Tableau formula on the xmetric engine, and the SQL in DuckDB.

What is the standard deviation of sales in each region?

Tableau

STDEVP([Sales])

SQL (DuckDB)

SELECT Region, stddev_pop(Sales) AS result
FROM input
GROUP BY Region
ORDER BY Region

East's four sales values give 96.01. South has one value: 0, since one value does not vary.

RegionResult
East96.01
Northnull
South0
West93.54

The Tableau formula and the SQL return the same 4 rows.

Where does a straight translation go wrong?

Common mistake

Why does DuckDB's stddev() give a bigger standard deviation?

In DuckDB, Snowflake and BigQuery, plain STDDEV means the sample standard deviation (divide by n - 1), Tableau's STDEV. STDEVP is the population version and divides by n, so write stddev_pop explicitly. South's single value shows it: 0 here, null for stddev.

Tableau

STDEVP([Sales])

Tempting SQL

SELECT Region, stddev(Sales) AS result
FROM input
GROUP BY Region
ORDER BY Region

SQL that matches

SELECT Region, stddev_pop(Sales) AS result
FROM input
GROUP BY Region
ORDER BY Region
RegionTableauTempting SQLSQL that matches
East96.0111196.01
Northnullnullnull
South0null0
West93.5410893.54

The SQL that matches returns the Tableau result on every row; the marked cells are where the tempting SQL differs.

What does STDEVP return for an all-null group?

North has two order lines and no sales value on either. Each result column is one mark, by Region.

CaseTableau, then SQL (DuckDB)EastNorthSouthWest
all-null groupSTDEVP([Sales])Region, stddev_pop(Sales)96.01null093.54

On every row, each Tableau formula and its SQL return the same value.

How do I write it in Snowflake or BigQuery?

The first example, written for each warehouse from its documentation. These are not run here; DuckDB is.

Snowflake

SELECT Region, STDDEV_POP(Sales) AS result
FROM input
GROUP BY Region
ORDER BY Region

Snowflake documentation

BigQuery

SELECT Region, STDDEV_POP(Sales) AS result
FROM input
GROUP BY Region
ORDER BY Region

BigQuery documentation

What does your own STDEVP formula return?

Edit the formula and run it on the 12 sample rows. Fields: [id], [Region], [Product], [Sales], [Units].

Runs in your browser on the xmetric engine. Nothing is uploaded.

Which functions go with it?

What do people ask about STDEVP?

Should I use STDEVP or STDEV?

Use the population version when your rows are every item you care about, not a sample. STDEV is the sample version.

Does STDEVP ignore nulls?

Yes. Empty values are left out of both the mean and the count, as in SQL.

What does STDEVP return for one value?

0: a single value has no spread. South has one sale and returns 0.

Where is this documented?