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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Invesco
Helper V
Helper V

Switch Based on if a slicer is selected in Power BI

Hi Experts

 

When the user selects a slicer in Power BI i want the switch function to use

MEASURE 1 = CALCULATE(DISTINCTCOUNT(dev_shc_shingrix_activity[employee_mud_id]), TREATAS(VALUES(dev_shc_shingrix_activity[practice]),shc_shingrix_practice[practice_name]))
 
When nothing is selected i want the swtich measure to use
Test = COUNTROWS(SUMMARIZE(dev_shc_shingrix_activity,dev_shc_shingrix_activity[employee_mud_id],dev_shc_shingrix_activity[external_hco_code]))+0
1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @Invesco ,

 

I think your issue should be caused by the relationship between the column in slicer and your data table. 

So when there is nothing selected in your slicer, due to the relationship, Power BI will always return the result in selected field.

I suggest you to create an unrelated Dimtable for slicer. And you need to add the filter from the slicer in [Test] and [Measure 1].

EX:

Test =
VAR _SELECT =
    VALUES ( DimTable[ColumeName] )
RETURN
    COUNTROWS (
        SUMMARIZE (
            FILTER (
                dev_shc_shingrix_activity,
                dev_shc_shingrix_activity[ColumeName] IN _SELECT
            ),
            dev_shc_shingrix_activity[employee_mud_id],
            dev_shc_shingrix_activity[external_hco_code]
        )
    ) + 0

If this reply still couldn't help you solve your issue, please share a sample file with me. And you can show me a screenshot with the result you want. This will make it easier for us to find the solution.

 

Best Regards,
Rico Zhou

 

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

5 REPLIES 5
v-rzhou-msft
Community Support
Community Support

Hi @Invesco ,

 

I think your issue should be caused by the relationship between the column in slicer and your data table. 

So when there is nothing selected in your slicer, due to the relationship, Power BI will always return the result in selected field.

I suggest you to create an unrelated Dimtable for slicer. And you need to add the filter from the slicer in [Test] and [Measure 1].

EX:

Test =
VAR _SELECT =
    VALUES ( DimTable[ColumeName] )
RETURN
    COUNTROWS (
        SUMMARIZE (
            FILTER (
                dev_shc_shingrix_activity,
                dev_shc_shingrix_activity[ColumeName] IN _SELECT
            ),
            dev_shc_shingrix_activity[employee_mud_id],
            dev_shc_shingrix_activity[external_hco_code]
        )
    ) + 0

If this reply still couldn't help you solve your issue, please share a sample file with me. And you can show me a screenshot with the result you want. This will make it easier for us to find the solution.

 

Best Regards,
Rico Zhou

 

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

foodd
Super User
Super User

Please provide sample data (with sensitive information removed) that covers your issue or question completely in a usable format (not as a screenshot).
https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Please show the expected outcome based on the sample data you provided.

https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

 

This allows members of the Forum to assess the state of the model, report layer, relationships, and any DAX applied.

miTutorials
Super User
Super User

Try the below.

 

 

Measure = IF(ISFILTERED(Columnname),MEASURE_1,Test )

 

Thanks for the feedback but not working when no filters are selected.

foodd
Super User
Super User

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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