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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
koorosh
Post Partisan
Post Partisan

Switch command including filter

Hi, Please check the attached file (testdays.pbix). I need a command to add to the switch command in the measure 'Dynamicmeasure' so that the slicer can filter the visual table on page one based on the following options.
Option1- filter table visual based on dafediff >60.

Option2- filter table visual based on datediff>100.

Option3- filter table visual based on dafediff>900.

 

Like what the filter pane does in photo1 and 2.

I do not want to use the filter pane. I want to use my own created slicer.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @koorosh ,

 

Try this code.

DynamicMeasure = 
VAR _SELECT =
    SELECTEDVALUE ( MeasureListTable[MeasureTitle] )
RETURN
    SWITCH (
        _SELECT,
        "More than 60",
            CALCULATE (
                SUM ( 'Table'[DifferenceDays] ),
                FILTER ( 'Table', 'Table'[DifferenceDays] > 60 )
            ),
        "More than 100",
            CALCULATE (
                SUM ( 'Table'[DifferenceDays] ),
                FILTER ( 'Table', 'Table'[DifferenceDays] > 100 )
            ),
        "More than 900",
            CALCULATE (
                SUM ( 'Table'[DifferenceDays] ),
                FILTER ( 'Table', 'Table'[DifferenceDays] > 900 )
            ),    CALCULATE(SUM('Table'[DifferenceDays]))   
    )

Result:

vrzhoumsft_0-1689064851658.png

 

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

4 REPLIES 4
Anonymous
Not applicable

Hi @koorosh ,

 

I suggest you to try code as below to create a measure.

DynamicMeasure = 
VAR _SELECT =
    SELECTEDVALUE ( MeasureListTable[MeasureTitle] )
RETURN
    SWITCH (
        _SELECT,
        "More than 60",
            CALCULATE (
                SUM ( 'Table'[DifferenceDays] ),
                FILTER ( 'Table', 'Table'[DifferenceDays] > 60 )
            ),
        "More than 100",
            CALCULATE (
                SUM ( 'Table'[DifferenceDays] ),
                FILTER ( 'Table', 'Table'[DifferenceDays] > 100 )
            ),
        "More than 900",
            CALCULATE (
                SUM ( 'Table'[DifferenceDays] ),
                FILTER ( 'Table', 'Table'[DifferenceDays] > 900 )
            )
    )

Result is as below.

vrzhoumsft_0-1689060794322.pngvrzhoumsft_1-1689060800371.pngvrzhoumsft_2-1689060808213.png

 

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.

 

Thanks. But we want to have all data in table visual when no option is selected. In this way, the visual would be empty.

Anonymous
Not applicable

Hi @koorosh ,

 

Try this code.

DynamicMeasure = 
VAR _SELECT =
    SELECTEDVALUE ( MeasureListTable[MeasureTitle] )
RETURN
    SWITCH (
        _SELECT,
        "More than 60",
            CALCULATE (
                SUM ( 'Table'[DifferenceDays] ),
                FILTER ( 'Table', 'Table'[DifferenceDays] > 60 )
            ),
        "More than 100",
            CALCULATE (
                SUM ( 'Table'[DifferenceDays] ),
                FILTER ( 'Table', 'Table'[DifferenceDays] > 100 )
            ),
        "More than 900",
            CALCULATE (
                SUM ( 'Table'[DifferenceDays] ),
                FILTER ( 'Table', 'Table'[DifferenceDays] > 900 )
            ),    CALCULATE(SUM('Table'[DifferenceDays]))   
    )

Result:

vrzhoumsft_0-1689064851658.png

 

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.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors
Top Kudoed Authors