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
sash
Frequent Visitor

DAX ALL vs. ALLEXCEPT

Hello,

 

I have a problem understanding the DAX filter functions. I want to do a GROUP BY SUM as a new column. I can get it to work using ALLEXCEPT, but not with the ALL function. Can anyone explain what I'm doing wrong?

 

This works as expected, returning total SUM of Value column of all the data: 

AllTable = CALCULATE(SUM(Sheet1[Value]); ALL(Sheet1)) 

 

This also works as expected, I get a SUM of grouped values by ColA and ColB:
ColumnAllExcept = CALCULATE(SUM(Sheet1[Value]); ALLEXCEPT(Sheet1; Sheet1[ColA]; Sheet1[ColB]))

 

I'm expecting that this returns the same as the previous formula (ColumnAllExcept), but it does not. It filters also on ColC, which it should not as it's explicitly defined that it should remove the filter from ColC:

ColumnAll = CALCULATE(SUM(Sheet1[Value]); ALL(Sheet1[ColC]))

 

The screenshot:

 

PowerBIForum_ALL_ALLEXCEPT.png

 

What am I doing wrong?

1 ACCEPTED SOLUTION
mattbrice
Solution Sage
Solution Sage

For a calculated column, when you use a CALCULATE every column in the table is transitioned from the row context to the filter context except when blocked by one of the 'ALL' functions like you used.  

 

In your last case you put :  ALL(Sheet1[ColC]), which if you look at row #1, while it does block the ColC value of 'Group XX' from transitioning to filter context, all the other columns still do. So it will sum up the 'Value' column for all the rows where 'ColA = Group 1'  and  'ColB = Group A' and 'Value = 1'.  It is this last filter why you are getting the results you are.  (And for completeness, it also filters the rows down to where 'AllTable = 136 and ColumnAllExcept = 10 )

 

So note when adding calculated columns is that unless explicity excluded, the filter context will also include other calculated columns.  So if you have two calculated columns that attempt to transition each other into the filter context, you end up with a circular dependency error which you may have seen.  Your use of 'ALL' and 'ALLEXCEPT' in the first two formulas avoids this as they block your newly created columns from being transitioned in. 

 

Hope this helps...

 

 

View solution in original post

2 REPLIES 2
mattbrice
Solution Sage
Solution Sage

For a calculated column, when you use a CALCULATE every column in the table is transitioned from the row context to the filter context except when blocked by one of the 'ALL' functions like you used.  

 

In your last case you put :  ALL(Sheet1[ColC]), which if you look at row #1, while it does block the ColC value of 'Group XX' from transitioning to filter context, all the other columns still do. So it will sum up the 'Value' column for all the rows where 'ColA = Group 1'  and  'ColB = Group A' and 'Value = 1'.  It is this last filter why you are getting the results you are.  (And for completeness, it also filters the rows down to where 'AllTable = 136 and ColumnAllExcept = 10 )

 

So note when adding calculated columns is that unless explicity excluded, the filter context will also include other calculated columns.  So if you have two calculated columns that attempt to transition each other into the filter context, you end up with a circular dependency error which you may have seen.  Your use of 'ALL' and 'ALLEXCEPT' in the first two formulas avoids this as they block your newly created columns from being transitioned in. 

 

Hope this helps...

 

 

Hi Matt,

 

Thank you very much for the explaination! I will look more into it, it seems that the DAX concepts are not as straightforward to understand as I thought. 🙂

 

 

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.