cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sash Frequent Visitor
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

Accepted Solutions
mattbrice Senior Member
Senior Member

Re: DAX ALL vs. ALLEXCEPT

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 Senior Member
Senior Member

Re: DAX ALL vs. ALLEXCEPT

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

sash Frequent Visitor
Frequent Visitor

Re: DAX ALL vs. ALLEXCEPT

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
New Topics Started Badges Coming

New Topics Started Badges Coming

We're releasing new versions of the badge that everyone's talking about. ;) Check your inbox for notifications.

MBAS 2020

Save the new date (and location)!

Our business applications community is growing—so we needed a different venue, resulting in a new date and location. See you there!

Difinity Conference

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors (Last 30 Days)