DIVIDE vs division operator in #dax

Posted by Marco Russo (SQLBI) on SQL Blog See other posts from SQL Blog or by Marco Russo (SQLBI)
Published on Thu, 24 Jul 2014 05:22:00 GMT Indexed on 2014/08/18 16:39 UTC
Read the original article Hit count: 449

Alberto Ferrari wrote an interesting article about DIVIDE performance in DAX. This new function has been introduced in SQL Server Analysis Services 2012 SP1, so it is available also in Excel 2013 (which still doesn’t have other features/fixes introduced by following Cumulative Updates…). The idea that instead of writing:

IF ( Sales[Quantity] <> 0, Sales[Amount] / Sales[Quantity], BLANK () )

you can write:

DIVIDE ( Sales[Amount], Sales[Quantity] )

There is a third optional argument in DIVIDE that defines the result in case the denominator (second argument) is zero, and by default its value is BLANK, so I omitted the third argument in my example.

Using DIVIDE is very important, especially when you use a measure in MDX (for example in an Excel PivotTable) because it raise the chance that the non empty evaluation for the result is evaluated in bulk mode instead of cell-by-cell. However, from a DAX point of view, you might find it’s better to use the standard division operator removing the IF statement. I suggest you to read Alberto’s article, because you will find that an expression applying a filter using FILTER is faster than using CALCULATE, which is against any rule of thumb you might have read until now!

Again, this is not always true, and depends on many conditions – trying to simplify, we might say that for a simple calculation, the query plan generated by FILTER could be more efficient – but, as usual, it depends, and 90% of the times using FILTER instead of CALCULATE produces slower performance. Do not take anything for granted, and always check the query plan when performance are your first issue!

© SQL Blog or respective owner

Related posts about Analysis Services

Related posts about DAX