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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

How to get multiple results from SWITCH() function?

Hi All,

 

I am trying to output multiple results depending on the selected field. 

 

These multiple results are an average, an upper bound and lower bound standard deviation:

Langutang_0-1600452368151.png

This works well as I have put every field into the lines, but I am trying to toggle to share of volume and get the wrong values

Langutang_1-1600452481972.png

These bounds and averages are calculations for the previous metric. So I am trying to make a switch statement for the lines in this visual to select the proper bounds and average depending on the selected metric with the following formula:

Bounds = 
switch(
    SELECTEDVALUE(Range[Metric]),
        "CRT", 'Verizon Call Reason'[YMax CRT],
        "CRT", 'Verizon Call Reason'[YMin CRT],
        "CRT", 'Verizon Call Reason'[Avg CRT],
        "% Share Volume",'Verizon Call Reason'[YMax V%],
        "% Share Volume", 'Verizon Call Reason'[YMin V%],
        "% Share Volume", 'Verizon Call Reason'[Avg V%],
        0
)

But this only gives me an aggregate of the upper, lower, and average line as something I do not need.

Langutang_2-1600452658016.png

 

How can I keep these bounds depending on the filter measure I select?

1 ACCEPTED SOLUTION
zaza
Resolver III
Resolver III

The logic behind switch is this:

 

if value equals X than "show me this", otherwise

if value equals Y than "show me that", ...

 

What you've wrote is this:

 

if value equals X than "show me this", otherwise

if value equals X than "show me that", ...

 

However this cannot work since X cannot equal 2 conditions at the same time. You cannot have "CRT" 3 times and "% Share Volume" also 3 times.

 

You need to create 3 separate switch functions:

 

Upper Bound = 
switch(
    SELECTEDVALUE(Range[Metric]),
        "CRT", 'Verizon Call Reason'[YMax CRT],
        "% Share Volume",'Verizon Call Reason'[YMax V%],
        0
)
Lower Bound = 
switch(
    SELECTEDVALUE(Range[Metric]),
        "CRT", 'Verizon Call Reason'[YMin CRT],
        "% Share Volume", 'Verizon Call Reason'[YMin V%],
        0
)
Average = 
switch(
    SELECTEDVALUE(Range[Metric]),
        "CRT", 'Verizon Call Reason'[Avg CRT],
        "% Share Volume", 'Verizon Call Reason'[Avg V%],
        0
)

View solution in original post

2 REPLIES 2
zaza
Resolver III
Resolver III

The logic behind switch is this:

 

if value equals X than "show me this", otherwise

if value equals Y than "show me that", ...

 

What you've wrote is this:

 

if value equals X than "show me this", otherwise

if value equals X than "show me that", ...

 

However this cannot work since X cannot equal 2 conditions at the same time. You cannot have "CRT" 3 times and "% Share Volume" also 3 times.

 

You need to create 3 separate switch functions:

 

Upper Bound = 
switch(
    SELECTEDVALUE(Range[Metric]),
        "CRT", 'Verizon Call Reason'[YMax CRT],
        "% Share Volume",'Verizon Call Reason'[YMax V%],
        0
)
Lower Bound = 
switch(
    SELECTEDVALUE(Range[Metric]),
        "CRT", 'Verizon Call Reason'[YMin CRT],
        "% Share Volume", 'Verizon Call Reason'[YMin V%],
        0
)
Average = 
switch(
    SELECTEDVALUE(Range[Metric]),
        "CRT", 'Verizon Call Reason'[Avg CRT],
        "% Share Volume", 'Verizon Call Reason'[Avg V%],
        0
)
Anonymous
Not applicable

This worked like a charm!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors