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
DAXROUNDROUNDUPROUNDDOWN
ExcelROUNDROUNDUPROUNDDOWN
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.

The syntax of ROUND, ROUNDUP and ROUNDDOWN
To the nearestROUND( <number>, <number of digits> )
Away from zeroROUNDUP( <number>, <number of digits> )
Toward zeroROUNDDOWN( <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.

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.

Tip

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.

Watch out!

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.

  1. 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
    StudentAverage
    Alma14.36
    Bilal9.82
    Chloé12.07

    Which formula should you write for “Rounded Average”?

  2. 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
    StudentAverage
    Alma14.36
    Bilal9.82
    Chloé12.07
  3. 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
    CustomerPallets
    North Hall30
    South Market24
    East Grocery13
  4. 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
    CustomerPallets
    North Hall30
    South Market24
    East Grocery13
  5. 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
    ClassMinutes
    Pottery135
    Origami59
    Painting240
  6. 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
    NameAge
    Léo37
    Mia42
    Sam19

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.