cancel
Showing results for 
Search instead for 
Did you mean: 
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...

 

 

sash
Frequent Visitor

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
August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power BI Dev Camp Session 24 without aka link and time 768x460.jpg

Ted's Dev Camp - July 28, 2022

Watch Session 24 of Ted's Dev Camp along with past sessions!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors