Variables (VAR) are used to:
• Improve performance
• Improve readability
• Simplify debugging
• Reduce complexity
To start using variables, follow two steps:
1. Create a measure and add the variables, by writing VAR var_name = [Valid DAX formula]
2. Return the calculation for the set variable by writing RETURN [Another DAX formula with the variable used as part of the calculation.
DAX formulas used in the video example:
Without VAR: YoY Growth % = DIVIDE( [Total Sales] - CALCULATE( [Total Sales], SAMEPERIODLASTYEAR( Dates[Date])),
CALCULATE( [Total Sales], SAMEPERIODLASTYEAR( Dates[Date])) )
With VAR: YoY Growth % VAR =
var SalesLY = CALCULATE( [Total Sales], SAMEPERIODLASTYEAR(Dates[Date]))
var Difference = [Total Sales] - SalesLY
Return DIVIDE( Difference, SalesLY)
To learn about Power BI and DAX formulas, follow us on social media: / centida
#PowerBI #DAX #VAR