Rules / DAX Expressions

Avoid using '1-(x/y)' syntax

warning AVOID_USING_'1-(X/Y)'_SYNTAX · ported · scope: Measure, CalculatedColumn, CalculationItem

What it checks

Expressions with a number, then plus or minus, then either SUM('Table'[Column]) followed by a division operator, or a call to DIVIDE. The common shape is 1 - SUM(Sales[Cost]) / SUM(Sales[Amount]).

Why it matters

Written that way the measure always returns a value. When there are no rows, the division is blank, one minus blank is one, and every empty cell in the matrix shows 100 percent. The visual fills with rows that should not be there, and the query does extra work to produce them. Written as a single DIVIDE over the difference, the measure is blank when the data is blank and the engine skips those rows.

How to fix it

Rewrite 1 - x / y as DIVIDE(y - x, y), and hold the shared denominator in a variable when it is used twice:

Margin % =
VAR Sales = SUM ( Sales[Amount] )
RETURN DIVIDE ( Sales - SUM ( Sales[Cost] ), Sales )

Quirks

Links

Check a model for this Improve this page