Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Visual fails when Legend uses a field already used in the DAX

I have a simple table of Sales by Product Types. 

I want to show Sales by Product Type for all 'Non Food' Sales in a Donut Visual.

When I bake the NOT 'Food' filter into the DAX, the donut fails to return the correct Product Type Split.

I have to create a 'Non Food Flag' column to use in the DAX so that the Product Type still works in the visual.

 

Any ideas why OR if there is a better way to achieve this?

sduffy_0-1629200278186.png

 

1 ACCEPTED SOLUTION
Jos_Woolley
Solution Sage
Solution Sage

Hi,

When you use:

 

Non Food Sales Count =
CALCULATE ( COUNT ( Sales[Sales ID] ), NOT ( Sales[Product Type] = "Food" ) )

 

i.e. the expression used as the filter within CALCULATE does not incorporate the FILTER function, it implicitly incorporates the column being passed within that expression to the ALL function, i.e. the above is equivalent to:

 

Non Food Sales Count = CALCULATE(COUNT(Sales[Sales ID]),FILTER(ALL(Sales[Product Type]),NOT(Sales[Product Type]="Food")))

 

This implicit ALL restores (overrides) the filtering coming from the Product Type, and so returns the same value for all Product Types, i.e. 7 (equivalent to the total sales which are either Electronics or Clothing).
Use either a version with FILTER:

 

Non Food Sales Count FILTER =
CALCULATE (
    COUNT ( Sales[Sales ID] ),
    FILTER ( Sales, NOT ( Sales[Product Type] = "Food" ) )
)

 

or else amend your version using KEEPFILTERS:

 

Non Food Sales Count KEEPFILTERS =
CALCULATE (
    COUNT ( Sales[Sales ID] ),
    KEEPFILTERS ( NOT ( Sales[Product Type] = "Food" ) )
)

 

Regards

View solution in original post

5 REPLIES 5
Jos_Woolley
Solution Sage
Solution Sage

Hi,

When you use:

 

Non Food Sales Count =
CALCULATE ( COUNT ( Sales[Sales ID] ), NOT ( Sales[Product Type] = "Food" ) )

 

i.e. the expression used as the filter within CALCULATE does not incorporate the FILTER function, it implicitly incorporates the column being passed within that expression to the ALL function, i.e. the above is equivalent to:

 

Non Food Sales Count = CALCULATE(COUNT(Sales[Sales ID]),FILTER(ALL(Sales[Product Type]),NOT(Sales[Product Type]="Food")))

 

This implicit ALL restores (overrides) the filtering coming from the Product Type, and so returns the same value for all Product Types, i.e. 7 (equivalent to the total sales which are either Electronics or Clothing).
Use either a version with FILTER:

 

Non Food Sales Count FILTER =
CALCULATE (
    COUNT ( Sales[Sales ID] ),
    FILTER ( Sales, NOT ( Sales[Product Type] = "Food" ) )
)

 

or else amend your version using KEEPFILTERS:

 

Non Food Sales Count KEEPFILTERS =
CALCULATE (
    COUNT ( Sales[Sales ID] ),
    KEEPFILTERS ( NOT ( Sales[Product Type] = "Food" ) )
)

 

Regards

Anonymous
Not applicable

Thanks Jos,

 

This is exactly what is needed.  Looks like I need to brush up on my DAX.

 

🙂

You're welcome! There aren't many people who don't need to brush up on their DAX, so you're certainly not alone! 😀

Anonymous
Not applicable

 Hi Tanushree,

 

Thanks for the input it is really appreciated.   

 

For info, the example provided is a simplification of a real business case DAX measure.  It is imperative that the filter is built into the DAX.  This measure will be reused across multiple reports and without the filter in the DAX, the measure is incomplete\incorrect.

 

Thanks

Tanushree_Kapse
Impactful Individual
Impactful Individual

Hi @Anonymous ,

You can use visual level filter for donut chart.
Filter out Food in basic filtering.

 

 

Mark this as a solution if I answered your question. Kudos are always appreciated.

Thanks!

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.