Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Anonymous
Not applicable

Measure doesn't work properly with VAR, but works as a separate measure

So I'm trying to apply time intelligence for a measure inside variable 

Actuals by brand=

VAR ActualsLY=CALCULATE([Actuals];CALCULATETABLE(SAMEPERIODLASTYEAR('date new'[Date]);'date new'[Date with Data]=true))
 
VAR DispAS=SELECTEDVALUE('Displayed as:'[Displayed as:])

RETURN
SWITCH( TRUE();
DispAS="Actuals";[Actuals];
DispAS="Actuals LY"; ActualsLY)
 
And it returns the same set of data as my "Actuals" measure
However if I do it as a separate measure, it works okay for me
Actuals LY =
CALCULATE([Actuals by Brand];CALCULATETABLE(DATEADD('date new'[Date];-12;MONTH);'date new'[Date with Data]=true))
 
1 REPLY 1
AlB
Community Champion
Community Champion

Hi @Anonymous 

Variables in DAX are immutable once they are assigned a value at declaration.  You need to use the measure if you want the result to be dependent on the context

Cheers

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.