DP-500 · Question #30
You have a Power BI dataset that contains the following measure. YTD Year-over-Year Var = DIVIDE ( ( [Sales Amount] - CALCULATE ( [Sales], SAMEPERIODLASTYEAR ( 'Calendar'[Date] ), 'Calendar'[Flag] =…
The correct answer is A. Replace both calculate functions by using a variable that contains the calculate function. To improve performance without changing logic, the repeated CALCULATE expression should be stored in a DAX variable and reused.
Question
Exhibit
Options
- AReplace both calculate functions by using a variable that contains the calculate function.
- BRemove the alternative result of blank( ) from the divide function.
- CCreate a variable and replace the values for [Sales Amount].
- DRemove "calendar[Flag] = "YTD" from the code.
How the community answered
(45 responses)- A80% (36)
- B13% (6)
- C2% (1)
- D4% (2)
Why each option
To improve performance without changing logic, the repeated `CALCULATE` expression should be stored in a DAX variable and reused.
The `CALCULATE` expression `CALCULATE ( [Sales], SAMEPERIODLASTYEAR ( 'Calendar'[Date] ), 'Calendar'[Flag] = "YTD" )` is repeated twice within the `DIVIDE` function. By assigning this complex expression to a variable (VAR), DAX can evaluate it once and reuse the result, thereby improving the measure's performance by avoiding redundant calculations without altering its logic or results.
Removing `BLANK()` from the `DIVIDE` function would change the measure's behavior when the denominator is zero or blank, affecting its logic.
`[Sales Amount]` is a simple reference, and replacing it with a variable would offer negligible performance improvement compared to optimizing the repeated `CALCULATE` expression.
Removing `'Calendar'[Flag] = "YTD"` would alter the filter context of the `CALCULATE` function, fundamentally changing the measure's logic and results.
Concept tested: DAX variable for performance optimization
Source: https://learn.microsoft.com/en-us/dax/var-dax
Topics
Community Discussion
No community discussion yet for this question.
