cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
webportal Member
Member

DAX ALLEXCEPT: How to remove all filters but one?

In my simple table, I have 3 columns:

  • Date
  • Sales
  • Store

These are the numbers: 

enter image description here

I want to calculate the sales for all the years for each store:

 

All Except Store = SUMX(ALLEXCEPT(Table1;Table1[Store]);Table1[Sales])

This is returning the following: 

enter image description here

It's nonsense! It's removing ALL the filters, so to calculate the sales for all the years and KEEP the filters on the store using ALLEXCEPT I can use:

 

All Except Store2 = CALCULATE(SUM(Table1[Sales]); ALLEXCEPT(Table1;Table1[Store]))

 

This one works.

 

But why doesn't it work with SUMX?

1 ACCEPTED SOLUTION

Accepted Solutions
Moderator v-yuezhe-msft
Moderator

Re: DAX ALLEXCEPT: How to remove all filters but one?

@webportal,

I got response from PG:

AllExcept behaves differently when used as a set filter in Calculate or when used to return a table. In the former case, all filters removed except for the filters on the specified columns.

SUMX(ALLEXCEPT(Table1;Table1[Store]);Table1[Sales]) means return a table of all rows in Table1. The returned table has all columns in Table1 except the [Store] column. Afterwards, calculate the sum by iterating over the returned table.


Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

8 REPLIES 8
Super User
Super User

Re: DAX ALLEXCEPT: How to remove all filters but one?

Hi @webportal

Can you share the pbix?

 

Moderator v-yuezhe-msft
Moderator

Re: DAX ALLEXCEPT: How to remove all filters but one?

@webportal,

I will consult this issue internally. And you can use the dax below instead.

Measure 2 = SUMX(FILTER(ALL(Table1);Table1[Store] =MAX(Table1[Store]));Table1[Sales])



Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
webportal Member
Member

Re: DAX ALLEXCEPT: How to remove all filters but one?

Ok, thanks a lot.
themistoklis New Contributor
New Contributor

Re: DAX ALLEXCEPT: How to remove all filters but one?

@webportal

 

Can you also check if this formula with SUMX works?

 

 

All Except Store = SUMX(ALLEXCEPT(Table1;Table1[Store]); CALCULATE(SUM(Table1[Sales])))

 

webportal Member
Member

Re: DAX ALLEXCEPT: How to remove all filters but one?

Yep, that one works too. CALCULATE has magical powers!

 

Here's the link to the pbix.

 

Thanks

Super User
Super User

Re: DAX ALLEXCEPT: How to remove all filters but one?

@webportal

You are using the ALLEXCEPT in an unusual manner.

Create a new table to see what the result of ALLEXCEPT(Table1;Table1[Store]) is. I think that will clarify what is going on.

Moderator v-yuezhe-msft
Moderator

Re: DAX ALLEXCEPT: How to remove all filters but one?

@webportal,

I got response from PG:

AllExcept behaves differently when used as a set filter in Calculate or when used to return a table. In the former case, all filters removed except for the filters on the specified columns.

SUMX(ALLEXCEPT(Table1;Table1[Store]);Table1[Sales]) means return a table of all rows in Table1. The returned table has all columns in Table1 except the [Store] column. Afterwards, calculate the sum by iterating over the returned table.


Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

themistoklis New Contributor
New Contributor

Re: DAX ALLEXCEPT: How to remove all filters but one?

@webportal

 

Also you need pay a good attention on Calculate function.

 

The CALCULATE function changes the context in which the data is filtered, and evaluates the expression in the new context that you specify. For each column used in a filter argument, any existing filters on that column are removed, and the filter used in the filter argument is applied instead.

Helpful resources

Announcements
Ask Amir Anything

Exclusive LIVE Community Event No. 2 – Ask Amir Anything

Next in our Triple A series: Ask Amir Netz questions about the latest updates, features and future.

October 2019 Community Highlights

October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.

New Solution Badges

New Solution Badges

Two waves of brand new solution badges are coming! Read the article for more information on our new community badges.

Analytics in Azure virtual event

Analytics in Azure virtual event

Experience a limitless analytics service built to ingest, prep, manage, and serve data for immediate use in Power BI.

Users Online
Currently online: 221 members 2,601 guests
Please welcome our newest community members: