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

Change to how slicers affect CALCULATE() in Sept 2021 update?

Has there been a change to how slicers filter data returned from a CALCULATE() expression in the latest (September 2021) update to Power BI Desktop? I know the CALCULATE() function has been updated, I wondered if this was an intended (or unintended) side-effect. Or whether I'm just going mad...

 

Basic example. I have a 'Sales' table with a 'Product' column. Let's say I have a product 'Bikes'.

 

I create a measure 'Total Sales' which is COUNTROWS(Sales).

I then create a measure 'Bike sales' which is CALCULATE([Total Sales], 'Sales'[Product] = "Bike")

Finally, I create another measure 'Other sales' which is CALCULATE([Total Sales], 'Sales'[Product] <> "Bike")

 

I have 1,000 Bike sales and 3,000 Other sales. Now I add a slicer to the page for Product.

When I select 'Bike' from the Product slicer, I would expect my Bike sales to show 1,000 and my Other sales to show 0 (or blank). When I select some other product, e.g. 'Skateboard' I would expect Bike sales to show 0 (or blank) and the Other sales figure to count only the rows where Product = 'Skateboard'.

 

However this is not happening. The slicer selection appears to have no bearing on the calculated measures. I select 'Skateboard' and I'm still seeing 1,000 sales for Bikes.

 

I'm sure this was not the default behaviour before. It is as though the CALCULATE() filters are overwriting the slicer selection. It means that when I select a product, I am getting an inaccurate display on my report because it is still counting 'Bikes'. Furthermore, when I select the 'Bike' product from the slicer I am also seeing no change to the 'Other sales' figure.

 

Did it always do this? Or did calculated measures return 0 or blank when a slicer selection resulted in the CALCULATE() evaluating to 0?

1 ACCEPTED SOLUTION
PaulDBrown
Community Champion
Community Champion

The issue is that when you are using a measure such as 

 

Bike Sales = 
CALCULATE([Total Sales], 'Sales'[Product] = "Bike")

 

It is in fact "sugar syntax" for 

 

Bike Sales =
CALCULATE (
    [Total Sales],
    FILTER ( ALL ( Sales[Product] ), 'Sales'[Product] = "Bike" )
)

 

So the measure will in fact remove any filter on Sales [Product]. Ie. the slicer from Sales [Product] won't affect the result. 

If you wish the slicer from Sales [Product] to filter, you can either use:

 

Bike Sales =
CALCULATE (
    [Total Sales],
    FILTER ( Sales , 'Sales'[Product] = "Bike" )
)

 

Or use a dimension table for product as the slicer.





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

2 REPLIES 2
PaulDBrown
Community Champion
Community Champion

The issue is that when you are using a measure such as 

 

Bike Sales = 
CALCULATE([Total Sales], 'Sales'[Product] = "Bike")

 

It is in fact "sugar syntax" for 

 

Bike Sales =
CALCULATE (
    [Total Sales],
    FILTER ( ALL ( Sales[Product] ), 'Sales'[Product] = "Bike" )
)

 

So the measure will in fact remove any filter on Sales [Product]. Ie. the slicer from Sales [Product] won't affect the result. 

If you wish the slicer from Sales [Product] to filter, you can either use:

 

Bike Sales =
CALCULATE (
    [Total Sales],
    FILTER ( Sales , 'Sales'[Product] = "Bike" )
)

 

Or use a dimension table for product as the slicer.





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Thanks. Either I have mis-remembered or I've always used dimension tables before. I generally do, but this is a basic 'training' dataset with a single table. I'll reference the syntax in your suggested solution in my example.

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.