Forum Discussion
Problem with field parameter and empty slicer
- 3 months ago
Hi PBI_VL , You cannot dynamically return a column directly from a measure, so use the disconnected table as the axis and then use TREATAS inside the measure to apply the correct column filter. For example, create a disconnected table that contains all category values from both columns, like:
AxisTable =
DISTINCT(
UNION(
SELECTCOLUMNS(Coverages, "Category", Coverages[AGE_CATEGORY]),
SELECTCOLUMNS(Coverages, "Category", Coverages[COVER_AGE_CATEGORY])
)
)Then use AxisTable[Category] on the Y axis and create a measure like:
ClientCount Dynamic =
VAR CoverSelected =
ISFILTERED(DimCover[Cover])
RETURN
IF(
CoverSelected,
CALCULATE(
[ClientCount],
TREATAS(VALUES(AxisTable[Category]), Coverages[COVER_AGE_CATEGORY])
),
CALCULATE(
[ClientCount],
TREATAS(VALUES(AxisTable[Category]), Coverages[AGE_CATEGORY])
)
)With this setup, when no Cover is selected the axis behaves like AGE_CATEGORY and when a Cover is selected it behaves like COVER_AGE_CATEGORY. You also avoid the unstable behaviour caused by the field parameter.
Hi PBI_VL , Thank you for reaching out to the Microsoft Community Forum.
The issue is coming from the way the field parameter is modelled. You are repeating the same field (COVER_AGE_CATEGORY) multiple times in the parameter and then filtering that parameter through DimCover. After you select a Cover and then clear the slicer, Power BI no longer resolves the parameter to a single row, so it behaves like multiple parameter rows are active and shows both AGE_CATEGORY and COVER_AGE_CATEGORY on the axis. That is why the visual works correctly on first load, but not after clearing the slicer.
I would not try to solve this with a “None” or default parameter option, because that is only a workaround. Stop using the field parameter for this logic and instead use a disconnected axis table with a measure that switches between AGE_CATEGORY and COVER_AGE_CATEGORY depending on whether a Cover is selected. That gives you stable behaviour where no Cover selected shows AGE_CATEGORY and selecting a Cover shows COVER_AGE_CATEGORY.
- PBI_VL3 months agoRegular Visitor
Thank you for the explanation. I understand the problem with the field parameter now.
I created the disconnected table but I'm not sure how to make the measure. How can I select a column depending on the value of the slicer? Can you please give me an example?
- v-hashadapu3 months agoCommunity Support
Hi PBI_VL , You cannot dynamically return a column directly from a measure, so use the disconnected table as the axis and then use TREATAS inside the measure to apply the correct column filter. For example, create a disconnected table that contains all category values from both columns, like:
AxisTable =
DISTINCT(
UNION(
SELECTCOLUMNS(Coverages, "Category", Coverages[AGE_CATEGORY]),
SELECTCOLUMNS(Coverages, "Category", Coverages[COVER_AGE_CATEGORY])
)
)Then use AxisTable[Category] on the Y axis and create a measure like:
ClientCount Dynamic =
VAR CoverSelected =
ISFILTERED(DimCover[Cover])
RETURN
IF(
CoverSelected,
CALCULATE(
[ClientCount],
TREATAS(VALUES(AxisTable[Category]), Coverages[COVER_AGE_CATEGORY])
),
CALCULATE(
[ClientCount],
TREATAS(VALUES(AxisTable[Category]), Coverages[AGE_CATEGORY])
)
)With this setup, when no Cover is selected the axis behaves like AGE_CATEGORY and when a Cover is selected it behaves like COVER_AGE_CATEGORY. You also avoid the unstable behaviour caused by the field parameter.
- PBI_VL3 months agoRegular Visitor
Thank you very much for the assistence! It works perfect now!