Forum Discussion
Dax Switch Calculation not working as expected
- 1 year ago
Hi cruncher
Thank you for the follow-up questions.
Since this has already been implemented using Field Parameters but is not filtering dynamically, I would recommend submitting this scenario as a feature request in the official Power BI Ideas forum.
The Product Team actively reviews suggestions there, and if others in the community upvote it, it may be considered for future updates.
https://ideas.fabric.microsoft.com/
I trust this information proves useful. If it does, kindly “Accept as solution” and give it a 'Kudos' to help others locate it easily.
Thank you.
Hi cruncher ,
Thanks for reaching out to the Microsoft fabric community forum.
danextian techies Thanks for your Prompt Response
Thanks for sharing the issue — you're right, this behavior is due to how DAX evaluates context in visuals, especially when SWITCH and DISTINCTCOUNT are used.
The problem arises because DISTINCTCOUNT(Country) is being evaluated in a broader filter context than expected, and not row-by-row in your matrix visual. So even though Region = SOUTH has only one country (C), your measure still falls through to the last condition and returns Country.
And i have modified the DAX aSs below and its working as expected
RegionOrCountryDisplay =
SWITCH (
TRUE (),
CALCULATE (
DISTINCTCOUNT ( SalesData[Country] ),
ALLEXCEPT ( SalesData, SalesData[Region] )
) = 1, SELECTEDVALUE ( SalesData[Region] ),
SELECTEDVALUE ( SalesData[Country] )
)
I’ve reviewed the scenario and have uploaded the PBIX file here for your reference.
Please feel free to take a look and let me know if anything else is required from my end. I’d be happy to assist further to help resolve the issue
If this post helped resolve your issue, please consider giving it Kudos and marking it as the Accepted Solution. This not only acknowledges the support provided but also helps other community members find relevant solutions more easily.
We appreciate your engagement and thank you for being an active part of the community.
Best regards,
LakshmiNarayana.
Thanks for looking into it. It return blank when North region is selected. It should show 2 Countries. Please check