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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
alaskanko
Frequent Visitor

Passing a Variable not working

Hi everyone,

 

I hope you will be able to help me to understand why the variables in DAX do not work as expected.

 

If I create a measure as the below, it doesn't work (doesn't return the desired outcome):

x_Achieved = 
VAR CurrentQTR = LOOKUPVALUE(Dates[Academic_Year_Quarter],Dates[Date],MAX(c_Enrolments[Date Exported On]))
VAR IsAchieved = FILTER(c_Enrolments,c_Enrolments[CompletionID]=2 && c_Enrolments[OutcomeID]=1 )
RETURN CALCULATE(COUNTROWS(c_Enrolments),FILTER(Dates_AED,Dates_AED[Academic_Year_Quarter]=CurrentQTR),IsAchieved)

 

Once I change the CurrentQTR to an actual string, it seems to work correctly (returns what is expected):

x_Achieved = 
//VAR CurrentQTR = LOOKUPVALUE(Dates[Academic_Year_Quarter],Dates[Date],MAX(c_Enrolments[Date Exported On]))
VAR IsAchieved = FILTER(c_Enrolments,c_Enrolments[CompletionID]=2 && c_Enrolments[OutcomeID]=1 )
RETURN CALCULATE(COUNTROWS(c_Enrolments),FILTER(Dates_AED,Dates_AED[Academic_Year_Quarter]="22/23 - Q4"),IsAchieved)

 

When I evaluate the CurrentQTR calculated using the LOOKUPVALUE and pass it into a Card visual, it shows exactly the desired value, "22/23 - Q4".

 

I am baffled as I have no idea why it has decided not to work...

 

I am sure it must be something silly and simple, but I am stuck.

 

Many thanks for your time 🙂

 

 

1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @alaskanko 

most probably because the filter context is different. What filter context do you have for your first code? filter context includes visual columns, rows, axis, filter pane setting, slicer selection. 

 

In your first code, try to

RETURN CurrentQTR

what do you get?

View solution in original post

1 REPLY 1
FreemanZ
Super User
Super User

hi @alaskanko 

most probably because the filter context is different. What filter context do you have for your first code? filter context includes visual columns, rows, axis, filter pane setting, slicer selection. 

 

In your first code, try to

RETURN CurrentQTR

what do you get?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors