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
campelliann
Post Patron
Post Patron

Calculate not filtering expression defined as variable?

Hi,


So I am having some difficulties figuring this, because I have not noticed before:

If I use the variable "soma Horas" inside calculate (situation 2), the expression returns the wrong result. It seems the table is not being filtered by project. 

I need to copy paste the entire variable for this to work (situation1).

 

These measures should return the same result, right?

Why is this?

Consumos Gerais_Team _1=

var soma_Horas = sum(Fact_ChangePoint[Regular hours])

var horas_visual_team = CALCULATE(sum(Fact_ChangePoint[Regular hours]),Fact_ChangePoint[Project]="PR00")
Return

horas_visual_team

 

Consumos Gerais_Team _2=

var soma_Horas = sum(Fact_ChangePoint[Regular hours])

var horas_visual_team = CALCULATE(soma_horas,Fact_ChangePoint[Project]="PR00")
Return

horas_visual_team

 

 
1 REPLY 1
v-xiaotang
Community Support
Community Support

Hi @campelliann 

Variables are always evaluated outside the filters your RETURN expression applies. In your Dax code, the RERURN  expression is 

var horas_visual_team = CALCULATE(soma_horas,Fact_ChangePoint[Project]="PR00")
Return
horas_visual_team

so the variable var soma_Horas = sum(Fact_ChangePoint[Regular hours]) has been evaluated before. 
FYI:
https://docs.microsoft.com/en-us/dax/best-practices/dax-variables

 


Best Regards,

Community Support Team _Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

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.