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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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