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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
osuraperera86
Regular Visitor

Nested Switch Function

I'm trying to calculate a dissatisfied value based on two criteria, Name and Year. Below is the formula I've written. For some reason, the values for 2019 and 2020 don't generate. Can anyone here help me? 

Highly Dissatisfied - Summary =

VAR TotalResponses =

CALCULATE(
    COUNT('Combined Raw Data'[Rating Value]),
    'Combined Raw Data'[Rating Value]<>blank(),
    'Mapping Level 1'[Service Area]="Overall",
    'Mapping Level 1'[Overall/Area]="Overall",
    'Combined Raw Data'[Rating  / Comment]="Rating"  
)

VAR HighlySatis =

CALCULATE(
    count('Combined Raw Data'[Rating Value]),
    'Combined Raw Data'[Rating Value]=1||
    'Combined Raw Data'[Rating Value]=2||
    'Combined Raw Data'[Rating Value]=3||
    'Combined Raw Data'[Rating Value]=4,
    'Mapping Level 1'[Service Area]="Overall",
    'Mapping Level 1'[Overall/Area]="Overall",
    'Combined Raw Data'[Rating  / Comment]="Rating"
)

Return
switch(
    SELECTEDVALUE('Combined Raw Data'[SL ABB]),
    "GBS",
    switch(
    SELECTEDVALUE('Year For Summary'[Year]),
    2019,0.0747,
    2020,0.0408,
    2021, Divide(HighlySatis,TotalResponses),
    2022, Divide(HighlySatis,TotalResponses)
    ),
    "FIS",
    switch(
    SELECTEDVALUE('Year For Summary'[Year]),
    2019,0.1562,
    2020,0.0890,
    2021, Divide(HighlySatis,TotalResponses),
    2022, Divide(HighlySatis,TotalResponses)
    ),
    "MDS",
    switch(
    SELECTEDVALUE('Year For Summary'[Year]),
    2019,0.1592,
    2020,0.1051,
    2021, Divide(HighlySatis,TotalResponses),
    2022, Divide(HighlySatis,TotalResponses)
    ),
    "WSS",
    switch(
    SELECTEDVALUE('Year For Summary'[Year]),
    2019,0.1652,
    2020,0.1304,
    2021, Divide(HighlySatis,TotalResponses),
    2022, Divide(HighlySatis,TotalResponses)
    ),
    "HRS",
    switch(
    SELECTEDVALUE('Year For Summary'[Year]),
    2019,0.1513,
    2020,0.0944,
    2021, Divide(HighlySatis,TotalResponses),
    2022, Divide(HighlySatis,TotalResponses)
    ),
    "CAS",
    switch(
    SELECTEDVALUE('Year For Summary'[Year]),
    2019,0.1261,
    2020,0.0701,
    2021, Divide(HighlySatis,TotalResponses),
    2022, Divide(HighlySatis,TotalResponses)
    ),
    "SAS",
    switch(
    SELECTEDVALUE('Year For Summary'[Year]),
    2019,0.2105,
    2020,0.1413,
    2021, Divide(HighlySatis,TotalResponses),
    2022, Divide(HighlySatis,TotalResponses)
    )
)
2 REPLIES 2
daXtreme
Solution Sage
Solution Sage

This code has a lot of repetitions. Please tidy this up, make it shorter, remove repetitions. Instead of || use the IN operator. It's not possible to tell you where the problem is without actual data.

Thank you for your suggestion; the essence of the problem is when I nest a switch function, the values calculated through a variable work but not the typed values highlighted in orange. 

osuraperera86_0-1669109947803.png

 

 

switch(
    SELECTEDVALUE('Combined Raw Data'[SL ABB]),
    "GBS",
    switch(
    SELECTEDVALUE('Year For Summary'[Year]),
    2019,0.0747,
    2020,0.0408,
    2021Divide(HighlySatis,TotalResponses),
    2022Divide(HighlySatis,TotalResponses)
    )




Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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