Knowledge Base
Open App
KB 102901

Use division instead of DIVIDE


When DIVIDE is used within an iterator, it’s possible to modify the filter context to exclude rows where the column used as the denominator is zero and replaced DIVIDE with the native division operator.

Remarks

DIVIDE always forces the Formula Engine to evaluate the expression and, in many scenarios, this may results in poor Storage Engine cache usage and worse performance compared to a native division operator.

Recommended articles:

Example 1

Replace DIVIDE with / division operator and use CALCULATE to modify the filter context to exclude rows where the column used as the denominator is zero.

Original code

SUMX ( 
    Sales, 
    DIVIDE ( Sales[Net Price], Sales[Quantity] )
)

Possible optimization

CALCULATE (
    SUMX ( 
        Sales, 
        Sales[Net Price] / Sales[Quantity]
    ),
    KEEPFILTERS ( Sales[Quantity] <> 0 )
)