Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin 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.
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.
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
Could you please advise?
Solved! Go to Solution.
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.
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.
could you pls provide some sample data and expected output?
Proud to be a Super User!
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
65 | |
63 | |
52 | |
37 | |
36 |
User | Count |
---|---|
82 | |
67 | |
61 | |
46 | |
45 |