DAX math and trig functions: every one with an example

A reference of all DAX math and trig functions, rounding (ROUND, ROUNDUP, ROUNDDOWN, MROUND, INT, TRUNC, CEILING, FLOOR, ISO.CEILING), division (DIVIDE, MOD, QUOTIENT), powers and logs, random numbers, CONVERT and CURRENCY, and the trigonometric functions, with examples.

Short answer: DAX math functions round (ROUND, MROUND, INT, TRUNC, CEILING, FLOOR), divide (DIVIDE, MOD, QUOTIENT), raise powers and logs (POWER, SQRT, EXP, LN, LOG), make random numbers (RAND, RANDBETWEEN), convert types (CONVERT, CURRENCY) and do trigonometry (SIN, COS, ATAN and more). They work like Excel's functions of the same name, with one difference to remember: negative numbers round differently in INT and TRUNC, and in CEILING and ISO.CEILING.

Which functions round?

FunctionExampleResult
ROUND ( n, digits )ROUND ( 1234.567, 1 )1234.6
ROUND with negative digitsROUND ( 1234.567, -2 )1200
ROUNDUP ( n, digits )ROUNDUP ( 1234.561, 2 )1234.57
ROUNDDOWN ( n, digits )ROUNDDOWN ( 1234.567, 0 )1234
MROUND ( n, multiple )MROUND ( 1.3, 0.2 )1.4
INT ( n )INT ( -2.5 )-3 (down to the next integer)
TRUNC ( n [, digits] )TRUNC ( -2.5 )-2 (cuts the decimals)
CEILING ( n, significance )CEILING ( 4.42, 0.05 )4.45
FLOOR ( n, significance )FLOOR ( 4.42, 0.05 )4.4
ISO.CEILING ( n [, significance] )ISO.CEILING ( -4.3, 2 )-4
EVEN, ODDEVEN ( 1.5 ), ODD ( 1.5 )2, 3
Rounding 1234.567 and -2.5

Microsoft notes CEILING follows Excel and ISO.CEILING the ISO definition; they agree for positive numbers. MROUND errors when the number and the multiple have different signs.

Round in the last step of a measure, or better not at all and let the format string show fewer decimals: rounding each row before summing changes totals.

-- price bands of 50 for a histogram column
Price Band = FLOOR ( 'Product'[List Price], 50 )

Which functions divide?

FunctionExampleResult
DIVIDE ( a, b [, alt] )DIVIDE ( 10, 0 )BLANK
MOD ( n, d )MOD ( 17, 5 )2
MOD with a negative numberMOD ( -3, 2 )1 (the sign of the divisor)
QUOTIENT ( a, b )QUOTIENT ( 17, 5 )3
GCD, LCMGCD ( 12, 18 ), LCM ( 4, 6 )6, 12
Division
-- every 7th day flag
Is Week Start = MOD ( 'Date'[Day Index], 7 ) = 0

-- hours and minutes from minutes
Duration Label = QUOTIENT ( [Minutes], 60 ) & "h " & MOD ( [Minutes], 60 ) & "m"

In depth: DIVIDE.

Which functions do powers, logs and signs?

FunctionExampleResult
POWER ( n, p ) or n ^ pPOWER ( 1.05, 3 )1.157625
SQRT ( n )SQRT ( 16 )4
SQRTPI ( n )SQRTPI ( 1 )1.7725 (square root of n times pi)
EXP ( n )EXP ( 1 )2.71828
LN ( n )LN ( EXP ( 2 ) )2
LOG ( n [, base] )LOG ( 8, 2 )3
LOG10 ( n )LOG10 ( 1000 )3
ABS ( n )ABS ( -12 )12
SIGN ( n )SIGN ( -12 )-1
FACT ( n )FACT ( 5 )120
PI ( )PI ( )3.14159
Powers, logs and signs
-- compound annual growth rate over the selected years
CAGR =
VAR FirstY = [First Year Revenue]
VAR LastY = [Last Year Revenue]
VAR Years = DISTINCTCOUNT ( 'Date'[Year] ) - 1
RETURN IF ( Years > 0, POWER ( DIVIDE ( LastY, FirstY ), 1 / Years ) - 1 )

Which functions convert, randomise and do trigonometry?

FunctionExampleResult
CONVERT ( value, type )CONVERT ( "42", INTEGER )42
CURRENCY ( value )CURRENCY ( 1234.56789 )1234.5679 (4 decimals)
RAND ( )RAND ( )a number from 0 to under 1
RANDBETWEEN ( a, b )RANDBETWEEN ( 1, 6 )1 to 6
DEGREES, RADIANSDEGREES ( PI ( ) )180
SIN, COS, TAN, COTSIN ( RADIANS ( 30 ) )0.5
ASIN, ACOS, ATAN, ACOTATAN ( 1 )0.7854
SINH, COSH, TANH, COTH and inversesCOSH ( 0 )1
Other math functions

CONVERT types are BOOLEAN, CURRENCY, DATETIME, DOUBLE, INTEGER and STRING; it errors when the value cannot convert. Trigonometry is rare in reports; one real use is distance between two coordinates (the haversine formula) for store and customer locations.

What goes wrong?

  • INT on negatives. INT ( -2.5 ) is -3; use TRUNC to cut toward zero.
  • Rounding before summing. Sum of rounded rows differs from the rounded sum; round once at the end, or format instead.
  • RAND in calculated columns. Changes on every refresh; seed data in Power Query instead.
  • MROUND with mixed signs. An error; keep number and multiple the same sign.

Where can you check this?

Where do you start?

Check your measures for ROUND inside an iterator and move the rounding to the format string. Statistical functions cover medians, percentiles and distributions.

Keep reading

More from the blog.

Every post

Next

Building this? Say hello.

A question about this post, a pattern you would build differently, or the next thing you want written out: Behnia reads every message.