cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Sean
Community Champion
Community Champion

ALL Function - Mystery?

Hello ALL,

I'm encountering a problem/issue with this simple formula.

The problem must be with my data but I can't seem to figure out where?

So here's the Measure => County Total

County Total = CALCULATE ( [Total Net], ALL(Payments[Subcategory], Payments[Category]) )

Total Net = SUM ( Payments[Net] )

Basically I want the County Total to be listed in all rows of a Matix (so I can use as Denominator for a % calculation)

So I created some sample data to post here - Please note the formula works as intended with the sample data!

 

So the problem must be with my real data but I can't seem to figure out what could be causing this?

Any suggestions/ideas about what to look for would be greatly appreciated!

 

So with my real data the Measure seems to ignore the ALL ... Payments[Category] part of the formula

 

ALL Function - not working.png

 

So there are 3 tables involved in this calculation Locations, Assets and Payments

Locations Table

StateCountyLocation
ST1County 1Location 1
ST1County 2Location 2
ST1County 2Location 3
ST1County 3Location 4
ST1County 3Location 5
ST1County 3Location 6
ST1County 3Location 7

 

Assets Table

AssetOperatorLocation
Asset 1Operator 1Location 1
Asset 2Operator 2Location 2
Asset 3Operator 2Location 2
Asset 4Operator 2Location 2
Asset 5Operator 2Location 3
Asset 6Operator 3Location 4
Asset 7Operator 3Location 5
Asset 8Operator 3Location 6
Asset 9Operator 4Location 7

 

Payments Table

CompanyPayment DateAssetNetCategorySubcategory
Company 112/1/2016Asset 1$300.00Cat 2Sub 2.1
Company 112/2/2016Asset 1$100.00Cat 3Sub 3.1
Company 312/15/2016Asset 2$100.00Cat 1Sub 1.1
Company 312/15/2016Asset 2$50.00Cat 1Sub 1.2
Company 312/15/2016Asset 2$25.00Cat 1Sub 1.3
Company 312/15/2016Asset 3$100.00Cat 1Sub 1.1
Company 312/15/2016Asset 3$50.00Cat 1Sub 1.2
Company 312/15/2016Asset 3$25.00Cat 1Sub 1.3
Company 312/15/2016Asset 4$100.00Cat 1Sub 1.1
Company 312/15/2016Asset 4$50.00Cat 1Sub 1.2
Company 312/15/2016Asset 4$25.00Cat 1Sub 1.3
Company 312/15/2016Asset 5$200.00Cat 1Sub 1.1
Company 312/15/2016Asset 5$150.00Cat 1Sub 1.2
Company 312/15/2016Asset 5$125.00Cat 1Sub 1.3
Company 412/20/2016Asset 6$75.00Cat 1Sub 1.2
Company 412/20/2016Asset 6$50.00Cat 1Sub 1.3
Company 412/20/2016Asset 7$75.00Cat 1Sub 1.2
Company 412/20/2016Asset 7$50.00Cat 1Sub 1.3
Company 412/20/2016Asset 8$75.00Cat 1Sub 1.2
Company 412/20/2016Asset 8$50.00Cat 1Sub 1.3
Company 212/21/2016Asset 7$25.00Cat 2Sub 2.2
Company 512/25/2016Asset 9$200.00Cat 2Sub 2.1

 

Again with the sample data the formula works fine - as intended!

I'm sure many of you have used something similar to calculate percentages.

 

Just hoping someone can suggest what to look for in my data that could be causing this???

 

Thanks!

 

 

 

 

 

2 ACCEPTED SOLUTIONS

@Sean,

Maybe it's related to some obscure cross-filtering issue from Payments to Asset to Location.

 

What do you get if you try:

County Total =
CALCULATE ( [Total Net], ALLEXCEPT ( Payments, Location[County] ) )

View solution in original post

Sean
Community Champion
Community Champion

Wow folks I figured it out! Smiley Happy

@Steve_WheelerMystery solved!

The culprit was a Conditional Column created in the Query Editor

That Column was called Category Sort and I basically used it so in charts the Categories show in order of importance and not A-Z

 

If anyone wants to see what actually happens just follow these steps:

1) Load all 3 sample tables I posted on Page 1

2) Write these 2 Measures

Total Net = SUM ( Payments[Net] )

County Total = CALCULATE ( [Total Net], ALL ( Payments[Subcategory], Payments[Category] ) )

3) Create a Matrix with County, Category and Subcategory in the Rows and then add the 2 Measures to the Values

Everything works great!

4) Now click Edit Queries and Add a Conditional Column in the Payments Table =>Category Sort

you can use the UI and basically

if Category is Cat 2 then 1, else if Category is Cat 3 then 2, otherwise 1 => OK => Close and Apply

so far so good nothing is affected yet!

5) Now go to the Data View => Payments table

=> select the Category Column => click Sort By Column => select the Category Sort column

6) Now go back and look at the Matrix => the County Total Measure no longer works as intended

 

HAPPY NEW YEAR!!! Smiley Happy

 

Related to this post

http://community.powerbi.com/t5/Desktop/ALL-function-ignored-inconsistent-functionality-when-also-us...

@bswylie@OwenAuger

View solution in original post

15 REPLIES 15
parry2k
Super User III
Super User III

Isn't the County Total measure suppose to be having sum function or it is just a typo

 

County Total = CALCULATE ( SUM([Total Net]), ALL(Payments[Subcategory], Payments[Category]) )

 






Did I answer your question? Mark my post as a solution.

Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





Also can you try  which is very less likely the issue but would be good to try.

 

County Total = CALCULATE ( SUM([Total Net]), ALL(Payments))

 






Did I answer your question? Mark my post as a solution.

Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





Sean
Community Champion
Community Champion

Hey thanks for replying.

1) Total Net is a already a Measure = SUM ( Payments[Net] ) I had listed it under the County Total Measure above

2) ALL(Payments) gives the Overall Total Net for all Counties

parry2k
Super User III
Super User III

You are right, you need total by county regardless what category/sub category it is. Not sure why this will work on sample data and not on real data.

 

I was referring to your "County Total" which missing SUM function, I'm sure that was typo.






Did I answer your question? Mark my post as a solution.

Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





@Sean,

Maybe it's related to some obscure cross-filtering issue from Payments to Asset to Location.

 

What do you get if you try:

County Total =
CALCULATE ( [Total Net], ALLEXCEPT ( Payments, Location[County] ) )

View solution in original post

Sean
Community Champion
Community Champion

@Steve_WheelerThank You! That did it and I get why/how it works! Smiley Happy

 

But I'm still wondering however why my original Measure works with the sample data I created but not with my real data

The relationships are set up the same way as in the sample - go figure...

Anyway Thanks again!

 

ALL Function - Mystery.png

 

That's good news, though the new version of the measure will likely cause problems if you want to also filter on Date, Company etc. - you'll need to add any slicer columns into the ALLEXCEPT to have the measure respect them I think, if that is required.

 

I can't see what's wrong with your original measure either, especially as you have single direction cross filters in place - there shouldn't be any weird filtering up to Asset and back down to Payment.

 

This shouldn't be hard!

 

I wonder if you get a different result in your original measure if you change the order of the columns in the ALL:

County Total = CALCULATE ( [Total Net], ALL(Payments[Category], Payments[Subcategory]) )

Or do you have any unexpected cross-pollination of Category and Subcategory - e.g. Sub 2.1 in Cat3 and Cat2?

Sean
Community Champion
Community Champion

@Steve_Wheeler

I'm just even more confused today...

I remembered this post here

http://community.powerbi.com/t5/Desktop/ALL-function-ignored-inconsistent-functionality-when-also-us...

1) So I loaded the tables in PowerPivot - and guess what my Measure produces the expected result with the real data!

2) Then I decided to try in a brand new pbix file - same thing - my Measure produces the expected result again with the real data!

I mean this is not a complicated measure! So it seems there's nothing wrong with my Data either.

I really really don't want to have to recreate this pbix file from scratch...

I've tried deleting all relationships and setting them up again - nothing seems to help fix the original pbix file

I've tried deleting all other tables in the data model except those 3 - no success

I've tried reversing the order of the columns in the Measure didn't make a difference BTW Thanks for the suggestion!

I've tried each column in its own ALL function - no change

And the weird thing is in PowerPivot and in a new pbix the Measure works as expected!

One final thought my Measure would not require the adjustments you mention regarding the Slicers!

Anyway if I figure it out I'll post back here!

But sadly it seems I'll have to recreate this file Smiley Sad

It's good that your measure works as expected in a new PBIX file.  It's BAD that you had to be inspired to create a new PBIX file for it to work - something's broken there, especially since ALLEXCEPT still strangely worked.  I suggest you raise it as an issue with Microsoft.

 

The other issue you linked and the Microsoft response "The current Microsoft view is that this is by design behavior and customers should build their model with dimension tables if they need to use ALL functions in their calculations." surprises me:

  • I did a couple of Google searches on ALL FILTER WRONG IGNORE etc. and didn't turn any of this up.  Searching now on Power BI Support gave up the link you posted but only if you picked the right specific words;
  • The documentation of this behaviour seems to just be in that one community post.  the MSDN doco for the ALL function (https://msdn.microsoft.com/en-us/library/ee634802.aspx) should be updated to show that, two months after the issue was acknowledged; and
  • That the behaviour of using dimension tables to use ALL functions is by design seems to go against the idea of a BI service for non-experts, and seems to contradict what's happening for you, in your new PBIX at least.

At least we made some progress on it via this community, though not as simple as it could be.

Sean
Community Champion
Community Champion

Wow folks I figured it out! Smiley Happy

@Steve_WheelerMystery solved!

The culprit was a Conditional Column created in the Query Editor

That Column was called Category Sort and I basically used it so in charts the Categories show in order of importance and not A-Z

 

If anyone wants to see what actually happens just follow these steps:

1) Load all 3 sample tables I posted on Page 1

2) Write these 2 Measures

Total Net = SUM ( Payments[Net] )

County Total = CALCULATE ( [Total Net], ALL ( Payments[Subcategory], Payments[Category] ) )

3) Create a Matrix with County, Category and Subcategory in the Rows and then add the 2 Measures to the Values

Everything works great!

4) Now click Edit Queries and Add a Conditional Column in the Payments Table =>Category Sort

you can use the UI and basically

if Category is Cat 2 then 1, else if Category is Cat 3 then 2, otherwise 1 => OK => Close and Apply

so far so good nothing is affected yet!

5) Now go to the Data View => Payments table

=> select the Category Column => click Sort By Column => select the Category Sort column

6) Now go back and look at the Matrix => the County Total Measure no longer works as intended

 

HAPPY NEW YEAR!!! Smiley Happy

 

Related to this post

http://community.powerbi.com/t5/Desktop/ALL-function-ignored-inconsistent-functionality-when-also-us...

@bswylie@OwenAuger

View solution in original post

I spent 2 days trying to figure this one out. Completely even forgot about setting that sort with a conditional calculated column. Cant belive something so silly would cause such trouble. 

 

Thank you for the solution !

@Sean,

Nice detective work.  That still seems like a bug to me.

Yes this is an annoying problem with "sort by column" in Power BI (but not PowerPivot).

Discussed here in one of the DAX Puzzles
http://www.sqlbi.com/daxpuzzle/unexpected-filter-behavior-in-calculate/

Owen Auger

Did I answer your question? Mark my post as a solution!

My Blog
Connect on Twitter
Connect on LinkedIn

@OwenAuger,

Good point.  So not a bug, but a poorly documented feature/ side-effect/ use case...   Now that we know with hindsight what to look for, it's simple!  Also documented nicely here: https://blog.crossjoin.co.uk/2015/12/15/power-bi-desktop-sort-by-column-and-dax-calculations-that-us...

 

 I wonder what we can do to avoid the next group also spending hours trying to figure out such an obscure issue?

Good point @Steve_Wheeler






Did I answer your question? Mark my post as a solution.

Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





Helpful resources

Announcements
User Groups Public Preview

Join us for our User Group Public Preview!

Power BI User Groups are coming! Make sure you’re among the first to know when user groups go live for public preview.

March Update

Check it Out!

Click here to read more about the March 2021 Updates!

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.