Forum Discussion
Preselected Custom Slicer
- 9 months ago
Hey there! π
This issue happens a lot when using preselected slicers β the default value works fine, but the slicer still shows all attributes from every country, right? π
Here are a couple of ways to fix it π
π©Ή Option 1: Quick check
Go to your slicer settings and turn off βShow items with no data.β
That usually fixes it right away, since it forces the slicer to only display values that exist for the selected country.But β if youβre using a custom visual like Preselected Slicer β it might ignore that setting. In that case, go for Option 2 π
π§ Option 2: Create a visibility measure
You can create a small measure that only returns 1 for attributes that actually have data for the selected country (and optionally disease).
Hereβs a simple version:
Show Attribute (by Country) =
VAR _Country = SELECTEDVALUE(ff_country_d[country_code])
RETURN
IF(
ISBLANK(_Country),
1, // show all if no country selected
IF(
CALCULATE(
COUNTROWS(ff_summary),
ff_summary[country_code] = _Country
) > 0,
1, 0
)
)
If you also want it to react to the disease filter:
Show Attribute (Country + Disease) =
VAR _Country = SELECTEDVALUE(ff_country_d[country_code])
VAR _Disease = SELECTEDVALUE(ff_summary[custom_disease_code])
RETURN
IF(
ISBLANK(_Country) && ISBLANK(_Disease),
1,
IF(
CALCULATE(
COUNTROWS(ff_summary),
(_Country = BLANK() || ff_summary[country_code] = _Country),
(_Disease = BLANK() || ff_summary[custom_disease_code] = _Disease)
) > 0,
1, 0
)
)β How to use it
Add your attribute field to the slicer.
In the Filters pane (for the visual), add the measure Show Attribute....
Filter it to show only values where it equals 1.
Optional: turn off Show items with no data just to be safe.
That should do the trick π―
Your slicer will now only show the attributes related to the selected country (and disease, if included), while keeping your preselection logic working perfectly.Hope it helps! π
Hey there! π
This issue happens a lot when using preselected slicers β the default value works fine, but the slicer still shows all attributes from every country, right? π
Here are a couple of ways to fix it π
π©Ή Option 1: Quick check
Go to your slicer settings and turn off βShow items with no data.β
That usually fixes it right away, since it forces the slicer to only display values that exist for the selected country.
But β if youβre using a custom visual like Preselected Slicer β it might ignore that setting. In that case, go for Option 2 π
π§ Option 2: Create a visibility measure
You can create a small measure that only returns 1 for attributes that actually have data for the selected country (and optionally disease).
Hereβs a simple version:
Show Attribute (by Country) =
VAR _Country = SELECTEDVALUE(ff_country_d[country_code])
RETURN
IF(
ISBLANK(_Country),
1, // show all if no country selected
IF(
CALCULATE(
COUNTROWS(ff_summary),
ff_summary[country_code] = _Country
) > 0,
1, 0
)
)
If you also want it to react to the disease filter:
Show Attribute (Country + Disease) =
VAR _Country = SELECTEDVALUE(ff_country_d[country_code])
VAR _Disease = SELECTEDVALUE(ff_summary[custom_disease_code])
RETURN
IF(
ISBLANK(_Country) && ISBLANK(_Disease),
1,
IF(
CALCULATE(
COUNTROWS(ff_summary),
(_Country = BLANK() || ff_summary[country_code] = _Country),
(_Disease = BLANK() || ff_summary[custom_disease_code] = _Disease)
) > 0,
1, 0
)
)
β How to use it
Add your attribute field to the slicer.
In the Filters pane (for the visual), add the measure Show Attribute....
Filter it to show only values where it equals 1.
Optional: turn off Show items with no data just to be safe.
That should do the trick π―
Your slicer will now only show the attributes related to the selected country (and disease, if included), while keeping your preselection logic working perfectly.
Hope it helps! π
- Anonymous9 months agoNot applicable
Hello,
I wanted to set default year as latest year for Country code = RO else "All" for other countries. Attr1 column is a text so I converted it to numeric using Value() dax function and output of Value() converted to text using FORMAT() dax function. However, it still showing all the years as a default values.
- Anonymous9 months agoNot applicable
Now, Default Value is showing as expected. In Preselected custom slicer it is still showing all the year value as default.