AVERAGEX, MINX and MAXX in DAX with examples

How AVERAGE, AVERAGEX, MIN, MINX, MAX and MAXX work in DAX, averaging per row against per group (average order value, average per month), best and worst months, latest dates, blanks in averages, and examples you can copy.

Short answer: AVERAGE, MIN and MAX work on one column. AVERAGEX, MINX and MAXX evaluate an expression for each row of a table you choose, then average, take the smallest or the largest. The table decides the meaning: AVERAGEX ( Sales, ... ) averages per sales line, AVERAGEX ( VALUES ( 'Date'[Month] ), [Revenue] ) averages per month. Blanks are skipped, so months without sales do not pull the average down.

"Average sale" can mean the average line, the average order or the average month. Each is a different AVERAGEX over a different table, with different numbers.

How do the averages differ?

-- average of a column: per sales line
Avg Line Amount = AVERAGE ( Sales[Amount] )

-- average order value: revenue per order
Avg Order Value = DIVIDE ( [Revenue], DISTINCTCOUNT ( Sales[Order ID] ) )

-- the same with AVERAGEX over orders
Avg Order Value X = AVERAGEX ( VALUES ( Sales[Order ID] ), [Revenue] )

-- average monthly revenue
Avg Month Revenue = AVERAGEX ( VALUES ( 'Date'[Month] ), [Revenue] )

-- average daily revenue over days with sales only
Avg Selling Day = AVERAGEX ( VALUES ( Sales[Order Date] ), [Revenue] )
Average perDenominatorValue
Sales line14,300 lines85 EUR
Order5,050 orders240 EUR
Selling day296 days with sales4,100 EUR
Month12 months101,000 EUR
The same year, four averages

All are correct; they answer different questions. Name each measure after its denominator.

How do MINX and MAXX help?

-- best month's revenue in the current year
Best Month = MAXX ( VALUES ( 'Date'[Month] ), [Revenue] )

-- worst month with sales
Worst Month = MINX ( VALUES ( 'Date'[Month] ), [Revenue] )

-- the name of the best month
Best Month Name =
VAR Best = [Best Month]
RETURN
    MAXX ( FILTER ( VALUES ( 'Date'[Month] ), [Revenue] = Best ), 'Date'[Month] )

-- latest order date per customer
Last Order = MAX ( Sales[Order Date] )

-- largest single order
Largest Order = MAXX ( VALUES ( Sales[Order ID] ), [Revenue] )

MAX and MIN also accept two values: MAX ( [Revenue], [Target] ), MIN ( [Bonus], 500 ).

What about blanks?

AVERAGEX skips rows where the expression is BLANK. Months with no sales are left out of Avg Month Revenue. If they should count as zero:

Avg Month incl Empty =
AVERAGEX ( VALUES ( 'Date'[Month] ), COALESCE ( [Revenue], 0 ) )

VALUES ( 'Date'[Month] ) comes from the Date table, so it lists all months in the filter, including those without sales; VALUES ( Sales[Order Date] ) lists only dates with sales.

What are the A variants?

AVERAGEA, MINA, MAXA and COUNTA also handle non-numeric values: TRUE counts as 1, FALSE as 0, and text as 0 in AVERAGEA. They are rarely needed in models with clean numeric columns.

What goes wrong?

  • AVERAGE where a weighted average is needed. The average of prices ignores quantities; use DIVIDE ( SUMX ( Sales, Qty * Price ), SUM ( Qty ) ).
  • Average of averages. Averaging regional averages ignores region size; average over the base rows.
  • The wrong table. AVERAGEX ( Sales, [Revenue] ) calls the measure per line; it is slow and means the same as average line revenue.
  • Partial periods. The current month drags down an average per month; exclude it or label it.

Where can you check this?

Where do you start?

Write Avg Order Value and Avg Month Revenue and give each a description that names its denominator. RANKX ranks the same per-row results instead of averaging them.

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.