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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Frankkk
New Member

Filter context within summarize

Dear Team,

 

I created a measure to calculate avg at the customer lvl but modified filter context, so it could work on other categories.

This measure is working as expected but only on "ch" category. The goal is to modify the filter context so values "ch" values would also populate on other categories.

Frankkk_1-1722974674920.png

I tried multiple options and the best shot was to put this logic into variable, so it could populate on other categories, but the outcome numbers are clearly wrong

Frankkk_3-1722975215605.png

 

Could you please advise?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Frankkk 

To modify the filter context in your DAX measure so that the "ch" category values are applied across other categories, we need to carefully manage the calculation context. The key is to calculate the "ch" category values independently from the context of other categories. Here's how you can adjust your DAX measure to achieve this:


VAR chQuantity =
CALCULATE(
SUM(fact[Total quantity]),
dim_product[Category] = "ch",
REMOVEFILTERS(dim_product)
)

VAR darkQuantity =
CALCULATE(
SUM(fact[Total Quantity]),
dim_product[Theme] = "dark"
)

VAR init =
SUMMARIZE(
fact,
fact[Customer Id],
"Avg",
DIVIDE(
chQuantity,
darkQuantity,
BLANK()
)
)

RETURN
AVERAGEX(init, [Avg])




VAR chQuantity: This variable calculates the total quantity for the "ch" category across all data, removing any existing filters on 'dim_product' to ensure it isn't affected by other category filters.

VAR darkQuantity: This calculates the total quantity for the "dark" theme. Here, we retain the natural filter context because we want the theme filter to apply only as needed.



 

 

 

 

Best Regards,

Jayleny

 

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

2 REPLIES 2
Anonymous
Not applicable

Hi @Frankkk 

To modify the filter context in your DAX measure so that the "ch" category values are applied across other categories, we need to carefully manage the calculation context. The key is to calculate the "ch" category values independently from the context of other categories. Here's how you can adjust your DAX measure to achieve this:


VAR chQuantity =
CALCULATE(
SUM(fact[Total quantity]),
dim_product[Category] = "ch",
REMOVEFILTERS(dim_product)
)

VAR darkQuantity =
CALCULATE(
SUM(fact[Total Quantity]),
dim_product[Theme] = "dark"
)

VAR init =
SUMMARIZE(
fact,
fact[Customer Id],
"Avg",
DIVIDE(
chQuantity,
darkQuantity,
BLANK()
)
)

RETURN
AVERAGEX(init, [Avg])




VAR chQuantity: This variable calculates the total quantity for the "ch" category across all data, removing any existing filters on 'dim_product' to ensure it isn't affected by other category filters.

VAR darkQuantity: This calculates the total quantity for the "dark" theme. Here, we retain the natural filter context because we want the theme filter to apply only as needed.



 

 

 

 

Best Regards,

Jayleny

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

ryan_mayu
Super User
Super User

could you pls provide some sample data and expected output?





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

Proud to be a Super User!




Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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