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
WZorn
Helper III
Helper III

Switching Calculation Filter Dynamically

I want to create a measure that tests if a set of data is empty when filtered.  If it is, then use a different filter to get another set of data.  Not sure the best way to describe it other than the by example below.

 

When sliced by Category, if data for M1 exists, I want to graph M1 values, if it doesn't, I want to graph M2 values.

My measure doesn't quite give me what I want. 

 

DATA:

CategoryMetricYearValue
Category 1M12020   3
Category 1M12021   8
Category 1M12022   3
Category 1M22020-FY   4
Category 1M22021-FY   9
Category 1M22022-FY   2
Category 2M12020   2
Category 2M12021   1
Category 2M12022   7
Category 3M22020-FY   2
Category 3M22021-FY   6
Category 3M22022-FY   4

 

A SLICER is setup for Catagory.

A LINE CHART is setup with Axis = "Year" and Values = "Measure"

 

Where 

Measure = IF(
     'Table'[M1 EMPTY],
     CALCULATE(
          SUM('Table'[Value]),
          FILTER('Table', 'Table'[Metric] = "M2")
     ),
     CALCULATE(
          SUM('Table'[Value]),
          FILTER('Table', 'Table'[Metric] = "M1")
     )
)
 
and
 
M1 EMPTY = ISEMPTY(
     CALCULATETABLE(
          'Table',
          'Table'[Metric] = "M1"
     )
)
 
 
MY RESULTS:
 
If I select "Category 2" in the slicer, I get what I expect only M1 Values:
WZorn_0-1663077866422.png

 

Selecting Category 3, shows only M2 values:

Category 3.JPG

 

BUT, when I select "Category 1", it's not giving what I expect.  I WANT M1 values only, but I get BOTH M1 and M2 values.

 Category 1.JPG

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @WZorn ,

Please try below dax formula:

Measure =
VAR cur_category =
    SELECTEDVALUE ( 'Table'[Category] )
VAR tmp_m1 =
    CALCULATETABLE (
        'Table',
        'Table'[Metric] = "M1",
        ALLSELECTED ( 'Table'[Category] )
    )
VAR sum_m1 =
    SUMX ( tmp_m1, [Value] )
VAR tmp_m2 =
    FILTER ( 'Table', 'Table'[Metric] = "M2" )
VAR sum_m2 =
    SUMX ( tmp_m2, [Value] )
VAR tmp_m3 =
    FILTER ( 'Table', 'Table'[Metric] = "M3" )
VAR sum_m3 =
    SUMX ( tmp_m3, [Value] )
RETURN
    SWITCH (
        cur_category,
        "Category 1", sum_m1,
        "Category 2", sum_m1,
        "Category 3", sum_m2
    )

Select "Category 1":

vbinbinyumsft_0-1663123153232.png

Select "Category 2":

vbinbinyumsft_1-1663123224008.png

Select "Category 3":

vbinbinyumsft_2-1663123245034.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_ Binbin Yu
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

1 REPLY 1
Anonymous
Not applicable

Hi @WZorn ,

Please try below dax formula:

Measure =
VAR cur_category =
    SELECTEDVALUE ( 'Table'[Category] )
VAR tmp_m1 =
    CALCULATETABLE (
        'Table',
        'Table'[Metric] = "M1",
        ALLSELECTED ( 'Table'[Category] )
    )
VAR sum_m1 =
    SUMX ( tmp_m1, [Value] )
VAR tmp_m2 =
    FILTER ( 'Table', 'Table'[Metric] = "M2" )
VAR sum_m2 =
    SUMX ( tmp_m2, [Value] )
VAR tmp_m3 =
    FILTER ( 'Table', 'Table'[Metric] = "M3" )
VAR sum_m3 =
    SUMX ( tmp_m3, [Value] )
RETURN
    SWITCH (
        cur_category,
        "Category 1", sum_m1,
        "Category 2", sum_m1,
        "Category 3", sum_m2
    )

Select "Category 1":

vbinbinyumsft_0-1663123153232.png

Select "Category 2":

vbinbinyumsft_1-1663123224008.png

Select "Category 3":

vbinbinyumsft_2-1663123245034.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_ Binbin Yu
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.