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

Get Fabric certified for FREE! Don't miss your chance! Learn more

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
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.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.