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
| Excel | SUM |
|---|---|
| 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.
It expects a single argument, a column of numbers written with its table, like Sales[Amount].
The report already contains this measure:
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.
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 Book Duration Dune 14 Emma 21 Ulysses 7 Candide 10 Which formula should you write for “Loan Days”?
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 Day Baked Unsold Monday 120 10 Tuesday 95 5 Wednesday 140 25
03.3.2AVERAGE
In Excel
| Excel | AVERAGE |
|---|---|
| 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.
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.
Direct useMeasureDifficulty
A class has handed in its papers, graded in the “Grades” table. Write the “Average Grade” measure.
Grades Student Grade Alma 12 Bilal 15 Chloé 9 Dario 16 Which formula should you write for “Average Grade”?
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 Day High Low 5/1/2026 18 8 5/2/2026 22 10 5/3/2026 20 6
03.3.3DIVIDE
In Excel
| Excel | IFERROR(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.
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.
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”?
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 Route Kilometers Liters R1 240 30 R2 160 20 R3 400 50
03.3.4COUNTROWS
In Excel
| Excel | ROWS, 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.
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.
Direct useMeasureDifficulty
A library keeps its catalog in the “Books” table, one book per row. Write the “Number of Books” measure.
Books Title Author Dune Herbert Emma Austen Ulysses Joyce Candide Voltaire Which formula should you write for “Number of Books”?
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 Guest Nights Alma 2 Bruno 3 Célia 1 Dario 6
03.3.5DISTINCTCOUNT
In Excel
| Excel | COUNTA(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.
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.
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 Book Reader Dune Alma Emma Bilal Ulysses Alma Candide Chloé Nadja Bilal Which formula should you write for “Readers”?
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 Order Customer 1 Paul 2 Léa 3 Paul 4 Paul 5 Léa
03.3.6FILTER
In Excel
| Excel | FILTER |
|---|---|
| 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.
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.
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.
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 Title Genre Dune Science fiction Emma Novel Ulysses Novel Candide Tale Which formula should you write for “Novels”?
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 Day Degrees 1/10/2026 -3 1/11/2026 2 1/12/2026 -1 1/13/2026 5
03.3.7CALCULATE + SUM
In Excel
| Excel | SUMIFS |
|---|---|
| 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.
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:
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.
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.
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 Book Genre Duration Emma Novel 14 Dune Science fiction 21 Ulysses Novel 10 Which formula should you write for “Novel Loan Days”?
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 Product Quantity Baguette 30 Croissant 12 Baguette 25 Tart 4
03.3.8CALCULATE + AVERAGE
In Excel
| Excel | AVERAGEIFS |
|---|---|
| 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.
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.
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 Book Genre Duration Dune Novel 14 Emma Novel 10 Atlas Science 21 Cosmos Science 7 Which formula should you write for “Average Novel Loan”?
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 Student Class Grade Alma 6A 12 Bilal 6A 16 Chloé 6B 9 Dario 6B 11
03.3.9CALCULATE + DIVIDE
In Excel
| Excel | SUMIFS(…)/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.
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.
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 Sport Minutes Sessions Yoga 180 3 Boxing 120 2 Yoga 90 1 Which formula should you write for “Average Yoga Session”?
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 Sport Minutes Sessions Yoga 180 3 Boxing 120 2 Yoga 90 1
03.3.10CALCULATE + COUNTROWS
In Excel
| Excel | COUNTIFS |
|---|---|
| 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.
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.
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 Guest Type Durand Suite Martin Double Petit Suite Roux Single Faure Double Which formula should you write for “Suite Bookings”?
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 Guest Type Durand Suite Martin Double Petit Suite Roux Single Faure Double
03.3.11CALCULATE + DISTINCTCOUNT
In Excel
| Excel | COUNTA(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.
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.
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 Reader Genre Léa Novel Léa Novel Tom Novel Tom Comic Inès Comic Which formula should you write for “Novel Readers”?
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 Reader Genre Léa Novel Léa Novel Tom Novel Tom Comic Inès Comic
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.
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:
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:
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:
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.
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 ||:
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:
With IN, you write the column only once, followed by IN and the list of values between braces:
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.
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 Room Channel Nights Suite Online 3 Suite Phone 2 Double Online 4 Suite Online 5 Which formula should you write for “Online Suite Nights”?
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 Parcel Weight Zone C-201 25 City C-202 8 Mountain C-203 5 City C-204 30 Mountain
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?
- 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" }.