DAX statistical functions: every one with an example

A reference of all DAX statistical functions, MEDIAN and PERCENTILE, standard deviation and variance, GEOMEAN, LINEST and LINESTX regression, distributions (NORM, T, CHISQ, BETA, POISSON, EXPON), CONFIDENCE, SAMPLE, RANK.EQ, COMBIN and PERMUT, with examples.

Short answer: DAX statistical functions describe spread and position (MEDIAN, PERCENTILE.INC, STDEV.S, VAR.S, GEOMEAN), fit lines (LINEST, LINESTX), work with distributions (NORM.DIST, T.INV, CHISQ.DIST, POISSON.DIST), give confidence intervals (CONFIDENCE.T), sample tables (SAMPLE) and count combinations (COMBIN, PERMUT). Most come in two forms: on a column (MEDIAN) and as an iterator over a table and an expression (MEDIANX). .S means sample, .P means population.

The average hides as much as it shows. A median order value next to the mean, or the 90th percentile of delivery time, tells readers what a typical customer experiences.

Which functions describe spread and position?

FunctionColumn formIterator formExample
medianMEDIANMEDIANXMEDIANX ( VALUES ( Orders[Order ID] ), [Order Value] )
percentile, k from 0 to 1PERCENTILE.INC, PERCENTILE.EXCPERCENTILEX.INC, PERCENTILEX.EXCPERCENTILE.INC ( Delivery[Days], 0.9 )
standard deviationSTDEV.S, STDEV.PSTDEVX.S, STDEVX.PSTDEVX.S ( VALUES ( 'Date'[Date] ), [Revenue] )
varianceVAR.S, VAR.PVARX.S, VARX.PVAR.P ( Sales[Amount] )
geometric meanGEOMEANGEOMEANXGEOMEANX ( Years, 1 + [Growth %] ) - 1
rank of a valueRANK.EQRANKXRANK.EQ ( Sales[Amount], Sales[Amount], DESC )
Spread and position

.INC includes the ends (k from 0 to 1); .EXC excludes them. Use .S when the rows are a sample of a larger group, .P when they are all of it.

-- typical and worst-case delivery
Median Days = MEDIAN ( Delivery[Days] )
P90 Days = PERCENTILE.INC ( Delivery[Days], 0.9 )

-- daily revenue volatility in the selection
Daily Revenue StDev = STDEVX.S ( VALUES ( 'Date'[Date] ), [Revenue] )

Microsoft notes that MEDIAN over an integer column can return integer or double, so a calculated column may need CONVERT ( ..., DOUBLE ) to keep one type.

How do you fit a trend line?

LINESTX ( table, y, x1 [, x2, ...] ) returns a one-row table with Slope1, Intercept, CoefficientOfDetermination (r²), StandardError, FStatistic and more:

Revenue Trend =
VAR Fit =
    LINESTX ( ALLSELECTED ( 'Date'[Month Index] ), [Revenue], 'Date'[Month Index] )
VAR Slope = SELECTCOLUMNS ( Fit, [Slope1] )
VAR Intercept = SELECTCOLUMNS ( Fit, [Intercept] )
RETURN Intercept + Slope * MAX ( 'Date'[Month Index] )

Trend R2 =
SELECTCOLUMNS (
    LINESTX ( ALLSELECTED ( 'Date'[Month Index] ), [Revenue], 'Date'[Month Index] ),
    [CoefficientOfDetermination]
)

LINEST takes columns of one table; LINESTX takes any expressions, which is what measures need. Months as an index (1, 2, 3, ...) keep the slope readable: revenue change per month.

Which distribution functions are there?

FamilyFunctionsExample
normalNORM.DIST, NORM.INV, NORM.S.DIST, NORM.S.INVNORM.S.INV ( 0.975 ) = 1.96
Student's tT.DIST, T.DIST.2T, T.DIST.RT, T.INV, T.INV.2TT.INV.2T ( 0.05, 20 ) = 2.086
chi-squaredCHISQ.DIST, CHISQ.DIST.RT, CHISQ.INV, CHISQ.INV.RTCHISQ.DIST.RT ( 6.2, 2 ) = 0.045
betaBETA.DIST, BETA.INVBETA.DIST ( 0.4, 2, 3, TRUE )
PoissonPOISSON.DISTPOISSON.DIST ( 2, 3, FALSE ) = 0.224
exponentialEXPON.DISTEXPON.DIST ( 1, 0.5, TRUE ) = 0.393
Distributions

Which functions give confidence and samples?

-- 95% confidence interval for the mean order value
CI Half Width =
CONFIDENCE.T ( 0.05, STDEV.S ( Orders[Value] ), COUNTROWS ( Orders ) )

-- 100 customers spread evenly over the key order, for a scatter chart
Customer Sample = SAMPLE ( 100, VALUES ( Customer[Customer Key] ), Customer[Customer Key] )

SAMPLE ( n, table, orderBy ) returns n rows spread evenly over the order, including the first and last; Microsoft advises grouping the table by the sort column to avoid duplicates. COMBIN ( 10, 3 ) is 120 ways to pick 3 of 10; PERMUT ( 10, 3 ) is 720 when order matters; COMBINA allows repeats.

In depth: error bars and confidence.

What goes wrong?

  • Mean when the data is skewed. Order values and delivery times have long tails; report the median and a percentile.
  • .S against .P. Small groups show the difference; pick by whether the rows are all of the population.
  • Iterating the wrong grain. STDEVX.S ( Sales, ... ) gives line-level spread; iterate VALUES ( 'Date'[Date] ) for daily spread.
  • Trend on dates. Slopes per day on date serial numbers are tiny and hard to read; use a month index.

Where can you check this?

Where do you start?

Add Median Days and P90 Days next to the average in your delivery or response-time report. Financial functions handle loans, depreciation and returns.

Keep reading

More from the blog.

Every post

Next

Building this? Say hello.

A question about this post, a pattern you would build differently, or the next thing you want written out: Behnia reads every message.