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
GROUPBY Region
ORDERBY Region
East's four sales values give 96.01. South has one value: 0, since one value does not vary.
Region
Result
East
96.01
North
null
South
0
West
93.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
GROUPBY Region
ORDERBY Region
SQL that matches
SELECT Region, stddev_pop(Sales) AS result
FROM input
GROUPBY Region
ORDERBY Region
Region
Tableau
Tempting SQL
SQL that matches
East
96.01
111
96.01
North
null
null
null
South
0
null
0
West
93.54
108
93.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.
Case
Tableau, then SQL (DuckDB)
East
North
South
West
all-null group
STDEVP([Sales])Region, stddev_pop(Sales)
96.01
null
0
93.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
GROUPBY Region
ORDERBY Region