Stop 07 · DAX FundamentalsTopics · 5/10

SUM, AVERAGE, MIN and MAX

Part of the Power BI Roadmap

In short

Total sales, average bill line, cheapest and costliest item: these four functions answer the first questions every manager asks, and they're the base of almost every measure.

SUM, AVERAGE, MIN and MAX aggregate a single column over whatever rows the current filters leave, giving totals, averages and the smallest or largest value.

The jaadu sorts banknotes from a shop's cash drawer into neat piles on the counter, holding the smallest note up in one hand and the largest in the other.

Think of it like this

Emptying the cash drawer

At closing time the shopkeeper counts the drawer. Add up all the notes (SUM), find the typical note (AVERAGE), the smallest and the largest (MIN, MAX). The key: he only counts the drawer of the shop and day he's looking at. That's the filter context.

Watch it happen

Five sales lines in the Pune store

200
0
450
1
blank
2
1200
3
150
4

1/5The filter (Store = Pune) leaves five Sales[Amount] values. One is blank.

The big ideas

What you need to know

One column in

These functions take a single column, like SUM ( Sales[Amount] ). For expressions, use SUMX and friends.

Filters decide the rows

In a matrix by city, SUM runs once per city cell on just that city's rows.

Blanks are ignored

AVERAGE skips blanks. Zeros are real values and are included.

Average of what?

AVERAGE ( Sales[Amount] ) is the average per sales line, not per bill or per customer.

See it in code

Walk through the code

dax
1Total Sales = SUM ( Sales[Amount] )2 3Avg Line Value = AVERAGE ( Sales[Amount] )4 5Cheapest Line = MIN ( Sales[Amount] )6 7Biggest Line = MAX ( Sales[Amount] )8 9Last Sale Date = MAX ( Sales[OrderDate] )

1/4The total of every Amount the current filters leave.

Put these in a matrix with Store[City] on rows. Each cell computes over that city's rows only.

Save yourself the pain

Common mistakes

Oops

Calling AVERAGE ( Sales[Amount] ) the average bill value.

Do this instead

It's per line. For per bill, divide total sales by DISTINCTCOUNT ( Sales[BillNo] ).

Oops

Writing SUM ( Sales[Qty] * Sales[Price] ).

Do this instead

SUM only accepts a column. Use SUMX ( Sales, Sales[Qty] * Sales[Price] ).

Your mission

Four numbers by city

~15 min

Quick check

Sales[Amount] has values 100, 300 and a blank in the current filter. What does AVERAGE return?

Go deeper

  1. 1Create Total Sales, Average Price, Lowest Price and Highest Price measures.
  2. 2Put them in a matrix by category and check one row by hand.
  3. 3Remember that AVERAGE averages rows, not orders or customers.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge