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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Axis
Regular Visitor

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
Super User
Super User

Hi @Axis 

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors