03.3Six basic functions

You now know what a measure is and where to store it. Six functions are enough to write your first measures. For each one, here is its syntax, then an exercise to do yourself. At the end, CALCULATE comes in to filter their results.

Type the formula as you would in Power BI. Like IntelliSense, the site suggests functions from the first letter, then tables and their columns, and at each argument what the function expects. Pick a suggestion with the arrow keys, then insert it with Tab.

03.3.1SUM

In Excel
ExcelSUM
Match

You need it as soon as you want the total of a column of numbers, like the revenue of all sales.

SUM adds up all the numbers in a column.

SUM( <column> )

It expects a single argument, a column of numbers written with its table, like Sales[Amount].

The report already contains this measure:

Revenue = SUM( Sales[Amount] )
Power BI accepts this DAX foryes, Measureyes, Calculated columnno, Calculated tableno, Virtual table

In the formulas that follow, you can therefore write either [Revenue] or SUM( Sales[Amount] ). Both give the same result.

Practice

Each exercise is solved with the function you just discovered. Two exercises per function, a direct use and a combined use, from easiest to hardest, on data other than the course data. Pick the right formula out of five.

  1. Direct useMeasureDifficulty

    A library keeps the duration of each loan, in days, in the “Loans” table. Write the “Loan Days” measure, the total of these durations.

    Loans
    BookDuration
    Dune14
    Emma21
    Ulysses7
    Candide10

    Which formula should you write for “Loan Days”?

  2. Combined useMeasureDifficulty

    Every day, a bakery records in the “Batches” table the loaves it baked and the loaves left unsold. Write the “Loaves Sold” measure.

    Batches
    DayBakedUnsold
    Monday12010
    Tuesday955
    Wednesday14025

03.3.2AVERAGE

In Excel
ExcelAVERAGE
Match

You need it when you are looking for the average value of a column, like the average amount of a sale.

AVERAGE calculates the average of the numbers in a column, that is their sum divided by how many there are.

AVERAGE( <column> )

Like SUM, it expects a column of numbers. It does not accept a measure.

Practice

Each exercise is solved with the function you just discovered. Two exercises per function, a direct use and a combined use, from easiest to hardest, on data other than the course data. Pick the right formula out of five.

  1. Direct useMeasureDifficulty

    A class has handed in its papers, graded in the “Grades” table. Write the “Average Grade” measure.

    Grades
    StudentGrade
    Alma12
    Bilal15
    Chloé9
    Dario16

    Which formula should you write for “Average Grade”?

  2. Combined useMeasureDifficulty

    Every day, a weather station records the highest and the lowest temperature in the “Readings” table. Write the “Average Range” measure, the gap between the average high and the average low.

    Readings
    DayHighLow
    5/1/2026188
    5/2/20262210
    5/3/2026206

03.3.3DIVIDE

In Excel
ExcelIFERROR(a/b,fallback)
Match

Your manager divides the revenue of each city by its target. For a city whose target has not been entered yet, the / operator divides by a blank value, and the visual shows infinity. DIVIDE avoids this trap and returns a blank result instead.

DIVIDE divides one number by another.

DIVIDE( <numerator>, <denominator>, [<alternate_result>] )

The first two arguments are required. The third one is not. It sets the result returned when the denominator is zero or blank, like the Toronto target below. If you leave it out, the comma before it goes too, and DIVIDE then returns a blank result.

Each argument can be a function, or a measure like [Revenue].

Practice

Each exercise is solved with the function you just discovered. Two exercises per function, a direct use and a combined use, from easiest to hardest, on data other than the course data. Pick the right formula out of five.

  1. Direct useMeasureDifficulty

    A school already has two measures, “Passed” and “Candidates.” The “Passed” measure counts the students who passed. The “Candidates” measure counts the candidates. Write the “Pass Rate” measure, the number of students who passed divided by the number of candidates.

    Which formula should you write for “Pass Rate”?

  2. Combined useMeasureDifficulty

    A carrier records, in the “Routes” table, the kilometers driven and the liters of fuel used on each route. Write the “Kilometers per Liter” measure, the total kilometers divided by the total liters.

    Routes
    RouteKilometersLiters
    R124030
    R216020
    R340050

03.3.4COUNTROWS

In Excel
ExcelROWS, or COUNTIFS with a condition
Match

COUNTROWS takes a table and returns a single number, its number of rows. The values the table holds do not matter, only its rows are counted. You use it to find out how many items a table contains.

In our data, each sale takes one row of the Sales table, so COUNTROWS returns the number of sales.

COUNTROWS counts the rows of a table.

COUNTROWS( [<table>] )

The brackets say that the argument is optional. Without it, COUNTROWS counts the rows of the table where the measure is stored. Here, you will always give it. It is the table whose rows you count, written by its name alone, like Sales.

Practice

Each exercise is solved with the function you just discovered. Two exercises per function, a direct use and a combined use, from easiest to hardest, on data other than the course data. Pick the right formula out of five.

  1. Direct useMeasureDifficulty

    A library keeps its catalog in the “Books” table, one book per row. Write the “Number of Books” measure.

    Books
    TitleAuthor
    DuneHerbert
    EmmaAusten
    UlyssesJoyce
    CandideVoltaire

    Which formula should you write for “Number of Books”?

  2. Combined useMeasureDifficulty

    A hotel records each booking in the “Bookings” table, with its number of nights. Write the “Nights per Booking” measure, with DIVIDE, the average length of a booking.

    Bookings
    GuestNights
    Alma2
    Bruno3
    Célia1
    Dario6

03.3.5DISTINCTCOUNT

In Excel
ExcelCOUNTA(UNIQUE(…))
Match

You need it when the same value comes back on several rows. Counting the rows of Sales gives 12 sales, but not 12 customers, because Orvane, for example, bought twice.

DISTINCTCOUNT counts the distinct values of a column. A value that comes back several times counts only once.

DISTINCTCOUNT( <column> )

It expects a column, of numbers or of text. The Sales[Customer ID] column, for example, has 12 rows, but some customers come back in it.

Practice

Each exercise is solved with the function you just discovered. Two exercises per function, a direct use and a combined use, from easiest to hardest, on data other than the course data. Pick the right formula out of five.

  1. Direct useMeasureDifficulty

    A library records each loan in the “Loans” table, with the reader’s name. The same reader often borrows several books. Write the “Readers” measure, the number of different readers.

    Loans
    BookReader
    DuneAlma
    EmmaBilal
    UlyssesAlma
    CandideChloé
    NadjaBilal

    Which formula should you write for “Readers”?

  2. Combined useMeasureDifficulty

    A bakery records each order in the “Orders” table, with the customer’s name. Write the “Orders per Customer” measure, with DIVIDE, the average number of orders a customer places.

    Orders
    OrderCustomer
    1Paul
    2Léa
    3Paul
    4Paul
    5Léa

03.3.6FILTER

In Excel
ExcelFILTER
Match

Your manager wants to read, side by side, the number of models in the catalog, 4, and the number of sedans, 2. A slicer on sedans would change both figures at once. So you need to keep the sedans of the Products table for the second calculation only.

FILTER keeps the rows of a table that meet a condition. It returns a table, not a single value.

FILTER( <table>, <condition> )

It expects two arguments, the table and then the condition. Here, the condition compares a column of the table to a value, like Products[Category] = "Sedan". A text value goes between double quotes.

FILTER moves to the first row of Products, A101 Rano. “Category” is Sedan, the condition answers TRUE, and the row is kept. Then comes A102 Lino. City car, FALSE, and the row is set aside. And so on, down to the last row.

Watch out!

The result of a measure is always a single value. So FILTER alone cannot be a measure. Here, the site shows the table it returns. To get a number from it, place it in a function that expects a table, like COUNTROWS. COUNTROWS( FILTER( Products, Products[Category] = "Sedan" ) ) returns 2, next to the 4 models of the catalog.

Practice

Each exercise is solved with the function you just discovered. Two exercises per function, a direct use and a combined use, from easiest to hardest, on data other than the course data. Pick the right formula out of five.

  1. Direct useCalculated tableDifficulty

    A library sorts its books by genre in the “Books” table. Create the “Novels” calculated table, which keeps only the books of the “Novel” genre.

    Books
    TitleGenre
    DuneScience fiction
    EmmaNovel
    UlyssesNovel
    CandideTale

    Which formula should you write for “Novels”?

  2. Combined useMeasureDifficulty

    Every morning, a weather station records the temperature in the “Readings” table. Write the “Frost Days” measure, the number of days below zero.

    Readings
    DayDegrees
    1/10/2026-3
    1/11/20262
    1/12/2026-1
    1/13/20265

03.3.7CALCULATE + SUM

In Excel
ExcelSUMIFS
Match

The sales rep in charge of Toronto wants to see, in the same table, the revenue of their customers next to the revenue of the whole dealership. A slicer on Toronto would change both figures at once. SUM adds up all the sales. So you need to filter its result, for this figure only.

CALCULATE can be used in several ways, which the rest of the course will cover in detail. Here, you use it for one thing only, filtering the result of one of the previous functions.

CALCULATE( <expression>, [<filter> …] )

The first argument is the calculation to perform, like SUM( Sales[Amount] ). The next ones are filters. Here, each filter is simple. It is a column compared to a value, like Customers[City] = "New York". CALCULATE then performs the calculation on only the rows that meet the filter.

For example, for the revenue of Toronto:

CALCULATE( SUM( Sales[Amount] ), Customers[City] = "Toronto" )
Power BI accepts this DAX foryes, Measureyes, Calculated columnno, Calculated tableno, Virtual table

SUM adds up only the amounts of the 3 Toronto sales, that is 300,000.

Unlike FILTER, which returns a table, CALCULATE returns a single value. So it can be a measure.

Here, you filter the Sales table from the City column of the Customers table. The relationship between these two tables makes this possible. The link of this relationship is the Customer ID column. Without this link, the filter on the city would not reach the sales. If a slicer ever changes nothing in your figures, check the relationship between the two tables first.

Here are these relationships as Power BI shows them, in its Model view. Click a relationship, in the diagram or in the list, to see the two columns it links.
Customers
City
Customer ID
Name
Type
Products
Brand
Category
Model
Product Code
Sales
Amount
Customer ID
Date
Price
Product Code
Qty
Sale ID
Manage relationships

This is a reproduction of the Power BI interface for teaching purposes. It differs from the real interface.

Practice

Each exercise is solved with the function you just discovered. Two exercises per function, a direct use and a combined use, from easiest to hardest, on data other than the course data. Pick the right formula out of five.

  1. Direct useMeasureDifficulty

    A library records each loan in the “Loans” table, with its genre and its duration in days. Next to the total number of loan days, it wants to read the total for novels alone. Write the “Novel Loan Days” measure, the total of the “Duration” column for the loans of the “Novel” genre only.

    Loans
    BookGenreDuration
    EmmaNovel14
    DuneScience fiction21
    UlyssesNovel10

    Which formula should you write for “Novel Loan Days”?

  2. Combined useMeasureDifficulty

    A bakery records each order in the “Orders” table. The baker wants to know what share of all sales the baguette represents. Write the “Baguette Share” measure.

    Orders
    ProductQuantity
    Baguette30
    Croissant12
    Baguette25
    Tart4

03.3.8CALCULATE + AVERAGE

In Excel
ExcelAVERAGEIFS
Match

AVERAGE calculates the average of a column, over the rows the visual lets through. CALCULATE can wrap it to change the rows taken into account. The filter it receives then applies to this average only.

In our data, the sales rep in charge of New York wants to read the average amount of their sales next to the average of the whole dealership.

CALCULATE filters the result of AVERAGE in the same way. The average is calculated only on the rows kept.

CALCULATE( AVERAGE( <column> ), [<filter> …] )

The first argument is the average to calculate, like AVERAGE( Sales[Amount] ). The next ones are filters, like Customers[City] = "New York".

Practice

Each exercise is solved with the function you just discovered. Two exercises per function, a direct use and a combined use, from easiest to hardest, on data other than the course data. Pick the right formula out of five.

  1. Direct useMeasureDifficulty

    A library records the duration of each loan, in days, in the “Loans” table. Write the “Average Novel Loan” measure, the average duration of a loan, for novels only.

    Loans
    BookGenreDuration
    DuneNovel14
    EmmaNovel10
    AtlasScience21
    CosmosScience7

    Which formula should you write for “Average Novel Loan”?

  2. Combined useMeasureDifficulty

    A school keeps its students’ grades in the “Grades” table, with their class. Write the “Gap with 6A” measure, the average of all the grades minus the average of class 6A.

    Grades
    StudentClassGrade
    Alma6A12
    Bilal6A16
    Chloé6B9
    Dario6B11

03.3.9CALCULATE + DIVIDE

In Excel
ExcelSUMIFS(…)/SUMIFS(…)
Match

DIVIDE divides one number by another and returns the result. CALCULATE can wrap it so that both numbers of the division come from the same rows, the ones that meet a filter.

In our data, the manager wants the average price of a car sold to customers in New York, that is their revenue divided by the number of cars they bought. Both numbers must then come from the New York sales only.

CALCULATE can filter the whole calculation of DIVIDE. The numerator and the denominator are then calculated on the same rows.

CALCULATE( DIVIDE( <numerator>, <denominator> ), [<filter> …] )

The first argument is the whole division, like DIVIDE( [Revenue], SUM( Sales[Qty] ) ). The next ones are filters, like Customers[City] = "New York".

Practice

Each exercise is solved with the function you just discovered. Two exercises per function, a direct use and a combined use, from easiest to hardest, on data other than the course data. Pick the right formula out of five.

  1. Direct useMeasureDifficulty

    A sports club records its classes in the “Classes” table. It already has two measures, “Minutes,” the sum of the “Minutes” column, and “Sessions Given,” the sum of the “Sessions” column. Write the “Average Yoga Session” measure, the number of minutes per yoga session.

    Classes
    SportMinutesSessions
    Yoga1803
    Boxing1202
    Yoga901

    Which formula should you write for “Average Yoga Session”?

  2. Combined useMeasureDifficulty

    The club wants to know the share of yoga in all the sports minutes of the “Classes” table. The “Minutes” measure adds up the “Minutes” column. Write the “Yoga Share” measure, using the “Minutes” measure.

    Classes
    SportMinutesSessions
    Yoga1803
    Boxing1202
    Yoga901

03.3.10CALCULATE + COUNTROWS

In Excel
ExcelCOUNTIFS
Match

COUNTROWS counts the rows of a table, the ones the visual lets through. CALCULATE can wrap it to change the rows counted. The filter it receives then applies to this count only.

In our data, the sales rep in charge of New York wants to read the number of their sales next to the number of sales of the whole dealership. COUNTROWS( Sales ) counts the 12 rows of the Sales table.

With CALCULATE, COUNTROWS counts only the rows that meet the filter.

CALCULATE( COUNTROWS( [<table>] ), [<filter> …] )

The first argument is the count to perform, like COUNTROWS( Sales ). The next ones are filters. A filter can be on a column of another table, like Customers[City] = "New York", or on a column of the counted table, like Sales[Price] = 50000.

Practice

Each exercise is solved with the function you just discovered. Two exercises per function, a direct use and a combined use, from easiest to hardest, on data other than the course data. Pick the right formula out of five.

  1. Direct useMeasureDifficulty

    A hotel records each booking on a row of the “Bookings” table, with the room type. Write the “Suite Bookings” measure, the number of bookings of the “Suite” type.

    Bookings
    GuestType
    DurandSuite
    MartinDouble
    PetitSuite
    RouxSingle
    FaureDouble

    Which formula should you write for “Suite Bookings”?

  2. Combined useMeasureDifficulty

    The hotel wants to know the share of suites in all the bookings of the “Bookings” table. Write the “Suite Share” measure.

    Bookings
    GuestType
    DurandSuite
    MartinDouble
    PetitSuite
    RouxSingle
    FaureDouble

03.3.11CALCULATE + DISTINCTCOUNT

In Excel
ExcelCOUNTA(UNIQUE(FILTER(…)))
Match

DISTINCTCOUNT counts the distinct values of a column. A value that comes back several times is counted only once. CALCULATE can wrap it to limit this count to the rows that meet a filter.

In our data, the manager wants to know how many customers in New York made a purchase. New York has 5 sales, but not 5 customers, because the same customer bought there several times.

With CALCULATE, DISTINCTCOUNT counts the distinct values among only the rows that meet the filter.

CALCULATE( DISTINCTCOUNT( <column> ), [<filter> …] )

The first argument is the count to perform, like DISTINCTCOUNT( Sales[Customer ID] ). The next ones are filters, like Customers[City] = "New York".

Practice

Each exercise is solved with the function you just discovered. Two exercises per function, a direct use and a combined use, from easiest to hardest, on data other than the course data. Pick the right formula out of five.

  1. Direct useMeasureDifficulty

    A library records each loan in the “Loans” table. Write the “Novel Readers” measure, the number of different readers who borrowed at least one novel.

    Loans
    ReaderGenre
    LéaNovel
    LéaNovel
    TomNovel
    TomComic
    InèsComic

    Which formula should you write for “Novel Readers”?

  2. Combined useMeasureDifficulty

    The library wants to know how many novels each novel reader borrows on average, from the “Loans” table. Write the “Novels per Reader” measure.

    Loans
    ReaderGenre
    LéaNovel
    LéaNovel
    TomNovel
    TomComic
    InèsComic

03.3.12Calculating with more than one condition

To filter with several conditions, write them one after the other in CALCULATE, separated by a comma. CALCULATE then keeps only the rows that meet all the conditions at once.

CALCULATE( <expression>, <filter 1>, <filter 2>, [<filter> …] )

There are many ways to filter a result in DAX. This one is among the simplest.

For example, for the revenue of the New York sales of more than 5 cars, at a price of 25,000:

CALCULATE( SUM( Sales[Amount] ), // adds up the amounts Customers[City] = "New York", // customers in New York Sales[Qty] > 5, // more than 5 cars Sales[Price] = 25000 // price of 25,000 )
Power BI accepts this DAX foryes, Measureyes, Calculated columnno, Calculated tableno, Virtual table

Of the 5 New York sales, 3 are over 5 cars, and 2 of these have a price of 25,000, V001 and V006. SUM adds up their amounts, that is 450,000.

The comma means “and”. You can also write it with AND, which you saw in the lesson on operators. These two formulas give the same result:

CALCULATE( SUM( Sales[Amount] ), Sales[Qty] > 5, Sales[Price] = 25000 )
Power BI accepts this DAX foryes, Measureyes, Calculated columnno, Calculated tableno, Virtual table
CALCULATE( SUM( Sales[Amount] ), AND( Sales[Qty] > 5, Sales[Price] = 25000 ) )
Power BI accepts this DAX foryes, Measureyes, Calculated columnno, Calculated tableno, Virtual table

The 4 sales of more than 5 cars at a price of 25,000 total 750,000.

To say “or,” use OR. CALCULATE then keeps the rows that meet at least one of the two conditions:

CALCULATE( SUM( Sales[Amount] ), OR( Sales[Qty] > 10, // more than 10 cars Sales[Price] = 50000 // or a price of 50,000 ) )
Power BI accepts this DAX foryes, Measureyes, Calculated columnno, Calculated tableno, Virtual table

One sale is over 10 cars, V008, and 4 sales have a price of 50,000. SUM adds up their 5 amounts, that is 700,000.

Watch out!

As you saw in the lesson on operators, AND and OR accept only two arguments. That is why && is preferred to AND, and || to OR. These operators chain as many conditions as you want.

The previous formula, written with ||:

CALCULATE( SUM( Sales[Amount] ), Sales[Qty] > 10 // more than 10 cars || Sales[Price] = 50000 // or a price of 50,000 )
Power BI accepts this DAX foryes, Measureyes, Calculated columnno, Calculated tableno, Virtual table
Tip

To keep several values of the same column, the IN operator is handier than repeating the column for each value. Without IN, you go through OR:

CALCULATE( SUM( Sales[Amount] ), // adds up the amounts OR( Customers[City] = "New York", // New York Customers[City] = "Chicago" // or Chicago ) )
Power BI accepts this DAX foryes, Measureyes, Calculated columnno, Calculated tableno, Virtual table

With IN, you write the column only once, followed by IN and the list of values between braces:

CALCULATE( SUM( Sales[Amount] ), // adds up the amounts Customers[City] IN { "New York", "Chicago" } // New York or Chicago )
Power BI accepts this DAX foryes, Measureyes, Calculated columnno, Calculated tableno, Virtual table

CALCULATE keeps the 9 sales of the customers in New York and Chicago. SUM adds up their amounts, that is 1,400,000.

Practice

Each exercise is solved with the function you just discovered. Two exercises per function, a direct use and a combined use, from easiest to hardest, on data other than the course data. Pick the right formula out of five.

  1. Direct useMeasureDifficulty

    A hotel records each booking in the “Bookings” table, with the room type, the booking channel and the number of nights. Write the “Online Suite Nights” measure, the sum of the nights of the suite bookings made online.

    Bookings
    RoomChannelNights
    SuiteOnline3
    SuitePhone2
    DoubleOnline4
    SuiteOnline5

    Which formula should you write for “Online Suite Nights”?

  2. Combined useMeasureDifficulty

    A carrier stores its parcels in the “Parcels” table, with their weight in kilos and their delivery zone. It handles separately the parcels of more than 20 kilos and the ones going to the mountains. Write the “Special Parcels” measure, with OR, the number of parcels that meet at least one of these two conditions.

    Parcels
    ParcelWeightZone
    C-20125City
    C-2028Mountain
    C-2035City
    C-20430Mountain

Quiz

The questions often rely on the course tables. Keep them in view in their floating window, which you can move and enlarge.

Question 1

What does CALCULATE( DISTINCTCOUNT( Sales[Customer ID] ), Customers[City] = "Toronto" ) return?

Question 2

You want the revenue of New York and Chicago. What does CALCULATE( SUM( Sales[Amount] ), Customers[City] = "New York", Customers[City] = "Chicago" ) return?

Question 3

What does DIVIDE( [Revenue], 0 ) return?

Key takeaways
  • SUM( <column> ) adds up the numbers in a column, and AVERAGE( <column> ) calculates their average.
  • DIVIDE( <numerator>, <denominator>, [<alternate_result>] ) divides one number by another. Its third argument, the alternate result, is the value returned when the denominator is zero or blank. For example, DIVIDE( [Revenue], 0, 0 ) returns 0. Without it, DIVIDE returns a blank result.
  • COUNTROWS( [<table>] ) counts the rows of a table.
  • DISTINCTCOUNT( <column> ) counts the distinct values of a column.
  • FILTER( <table>, <condition> ) returns a table. Place it in a function that expects a table, like COUNTROWS.
  • CALCULATE( <expression>, [<filter> …] ) has several uses. The simplest one is to perform a calculation on only the rows that meet a filter, like Customers[City] = "New York".
  • In CALCULATE, several conditions are written one after the other, separated by a comma. The comma means “and,” like AND. CALCULATE then keeps the rows that meet all the conditions.
  • To say “or,” use OR.
  • AND and OR accept only two arguments.
  • && and || have no such limit, and you can chain them.
  • To keep several values of the same column, IN saves you from repeating the column, like Customers[City] IN { "New York", "Chicago" }.