13.6Math functions
You know these calculations from Excel. These functions bring them to DAX, to round, take the integer part, the absolute value or the remainder of a division. The examples start from the average amount of a sale, 141,666.67.
13.6.1ROUND, ROUNDUP and ROUNDDOWN
In Excel
| DAX | ROUND | ROUNDUP | ROUNDDOWN |
|---|---|---|---|
| Excel | ROUND | ROUNDUP | ROUNDDOWN |
| Match |
You need them when the number itself must be rounded, and not just its display, for example 142,000 rather than 141,666.67 in a calculation or a file. For display alone, the formatting of the visual is enough.
ROUND rounds a number to the number of digits requested. ROUNDUP and ROUNDDOWN round in the same way, but always in the same direction.
| To the nearest | ROUND( <number>, <number of digits> ) |
|---|---|
| Away from zero | ROUNDUP( <number>, <number of digits> ) |
| Toward zero | ROUNDDOWN( <number>, <number of digits> ) |
All three expect the number to round, then the number of digits to keep after the decimal point. A negative number rounds to the left of the decimal point, to the thousands for -3.
- ROUND( 141666.67, 0 ) returns 141,667.
- ROUND( 141666.67, -3 ) returns 142,000.
- ROUNDDOWN( 141666.67, -3 ) returns 141,000.
- ROUNDUP( 141666.67, -3 ) returns 142,000.
| [Average] | [ROUND 0] | [ROUND -3] | [ROUNDDOWN -3] | [ROUNDUP -3] | |
|---|---|---|---|---|---|
| 1 | 141666.666666667 | 141667 | 142000 | 141000 | 142000 |
This is a reproduction of the Power BI interface for teaching purposes. It differs from the real interface.
141,666.67 is the average amount of a sale, 1,700,000 divided by 12.ROUNDUP always rounds away from zero, and ROUNDDOWN always toward zero. For a positive number, that means up and down. For a negative number, the rule stays the same, and only the direction on the number line changes. ROUNDDOWN moves toward zero and goes up, so ROUNDDOWN( -1.5, 0 ) returns -1. ROUNDUP moves away from it and goes down, so ROUNDUP( -1.5, 0 ) returns -2.
ROUND changes the value. The display format of a measure, set in the Measure tools tab, only changes how it looks. To show 142,000 without distorting the totals, the format is often the better choice.
In a DAX formula, decimals are always written with a point, as in 141666.67. The comma separates the arguments.
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 columnDifficulty
A school keeps each student’s average grade, with two decimals, in the “Students” table. The report card shows only one. Add to the “Students” table the calculated column “Rounded Average,” rounded to one decimal.
Students Student Average Alma 14.36 Bilal 9.82 Chloé 12.07 Which formula should you write for “Rounded Average”?
Combined useMeasureDifficulty
The school wants to show the class average with a single decimal, based on the “Average” column of the “Students” table. Write the measure “Class Average.”
Students Student Average Alma 14.36 Bilal 9.82 Chloé 12.07 Direct useCalculated columnDifficulty
A carrier loads 12 pallets per truck. A half-full truck still leaves. Add to the “Orders” table the calculated column “Trucks,” the number of trucks needed.
Orders Customer Pallets North Hall 30 South Market 24 East Grocery 13 Combined useMeasureDifficulty
The carrier can also group all the orders of the “Orders” table into the same 12-pallet trucks. The “Pallets” column gives the pallets of each order. Write the measure “Trucks When Grouped.”
Orders Customer Pallets North Hall 30 South Market 24 East Grocery 13 Direct useCalculated columnDifficulty
A craft studio records the length of each class in minutes. Add to the “Workshops” table the calculated column “Full Hours,” the number of complete hours.
Workshops Class Minutes Pottery 135 Origami 59 Painting 240 Combined useCalculated columnDifficulty
A club groups its members by ten-year bands, 30 for ages 30 to 39. Add to the “Members” table the calculated column “Age Group,” the age rounded down to the ten.
Members Name Age Léo 37 Mia 42 Sam 19
The rest of this lesson is part of izyDAX Pro
You have just read the first section. The next one, its animations, the exercises and the summary are waiting for you with izyDAX Pro, in a single payment.