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
Anonymous
Not applicable

How is a table value handled/processed in the expression of CALCULATE?

I'm hoping someone can help me understand the logic of how the expression in a CALCULATE function works when there's only inserted a table column in it. Beneath I've created an example:

Fact table:


Type:        Value:
A                  1

B                  5

C                  2

Slicer:
A slicer that filters out "type = C".

Measures:

Following measures is the source of my question:

 

measure1 = 
   var ValuesColumn = VALUES('Table'[Value])
   Return
   CALCULATE(COUNTA('Table'[Value];ValuesColumn)
measure2 = 
var ValuesColumn = VALUES('Table'[Value])
Return
CALCULATE(COUNTA('Table'[Value];FILTER('Table';'Table'[Value] in ValuesColumn)


I know this is a very simplified setup but my question is basically how these 2 approaches are handled/processed? And do they even yield a different result?

 

1 ACCEPTED SOLUTION
d_gosbell
Super User
Super User

In your example with just a single table both measures will returnt the same value, but the filter context of both is slightly different so in a more complicated scenario the results could be different.

 

Basically in both measures the variable ValuesColumn will return a single column table with a single value of "2"

 

measure1 says to count the values in the Table[Value] column where  the value in Table[Value] is "2" (from the variable)

 

measure2 also says to count the values in the Table[Value column, but the filter this time is on the entire "Table" table (so both the Type and Value columns) so it is effectively filtered for Type = "C" and Value = 2.

 

In this single table example both measure1 and measure2 will return the same value, but the extra columns in the filter condition in measure2 could change things in more complicated scenarios. 

View solution in original post

3 REPLIES 3
v-shex-msft
Community Support
Community Support

Hi @Anonymous ,

I'd like to suggest you take a look at following blog about variable use in Dax calculation:

Variables in DAX 
Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
d_gosbell
Super User
Super User

In your example with just a single table both measures will returnt the same value, but the filter context of both is slightly different so in a more complicated scenario the results could be different.

 

Basically in both measures the variable ValuesColumn will return a single column table with a single value of "2"

 

measure1 says to count the values in the Table[Value] column where  the value in Table[Value] is "2" (from the variable)

 

measure2 also says to count the values in the Table[Value column, but the filter this time is on the entire "Table" table (so both the Type and Value columns) so it is effectively filtered for Type = "C" and Value = 2.

 

In this single table example both measure1 and measure2 will return the same value, but the extra columns in the filter condition in measure2 could change things in more complicated scenarios. 

Anonymous
Not applicable

Thank you for the explanation and examples @d_gosbell 

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.