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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

Write code in easier way

Hi, 

 

I wonder if someone can help me to make this code shorter? It works perfectly , buy I need to review it and it's hard to understand when there is so much text.

SLA FORM OTC = IF('SNOW(sn_sm_finance_request)'[priority] = "1 - Critical" && 'SNOW(sn_sm_finance_request)'[assignment_group]= "FSM OTC Front Office Spain" || 'SNOW(sn_sm_finance_request)'[priority] = "1 - Critical" && 'SNOW(sn_sm_finance_request)'[assignment_group]= "FSM OTC Shared Service Center"; "0,4"; IF('SNOW(sn_sm_finance_request)'[priority] = "2 - High" && 'SNOW(sn_sm_finance_request)'[assignment_group]= "FSM OTC Front Office Spain" || 'SNOW(sn_sm_finance_request)'[priority] = "2 - High" && 'SNOW(sn_sm_finance_request)'[assignment_group]= "FSM OTC Shared Service Center"; "0,8"; IF('SNOW(sn_sm_finance_request)'[priority] = "3 - Moderate" && 'SNOW(sn_sm_finance_request)'[assignment_group]= "FSM OTC Front Office Spain" || 'SNOW(sn_sm_finance_request)'[priority] = "3 - Moderate" && 'SNOW(sn_sm_finance_request)'[assignment_group]= "FSM OTC Shared Service Center"; "3"; IF('SNOW(sn_sm_finance_request)'[priority] = "4 - Low" && 'SNOW(sn_sm_finance_request)'[assignment_group]= "FSM OTC Front Office Spain" || 'SNOW(sn_sm_finance_request)'[priority] = "4 - Low" && 'SNOW(sn_sm_finance_request)'[assignment_group]= "FSM OTC Shared Service Center"; "3"; IF('SNOW(sn_sm_finance_request)'[priority] = "" && 'SNOW(sn_sm_finance_request)'[assignment_group]= "FSM OTC Front Office Spain" || 'SNOW(sn_sm_finance_request)'[priority] = "" && 'SNOW(sn_sm_finance_request)'[assignment_group]= "FSM OTC Shared Service Center";"3"; "" )))))

Regards 

Albin

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi Albin,

 

This is a calculated column by the looks of it.

I would suggest declaring some variables and using the SWITCH function.

 

Here is one way of doing it where I have stored almost every column value and constant in a variable. The SWITCH function replaces most of the nested IFs. I have also simplified the expression of the logical tests.

 

SLA FORM OTC =
VAR P = 'SNOW(sn_sm_finance_request)'[priority]
VAR AG = 'SNOW(sn_sm_finance_request)'[assignment_group]
VAR Spain = "FSM OTC Front Office Spain"
VAR Shared = "FSM OTC Shared Service Center"
VAR Spain_Shared = { Spain; Shared }
VAR P1 = "1 - Critical"
VAR P2 = "2 - High"
VAR P3 = "3 - Moderate"
VAR P4 = "4 - Low"
VAR PBlank = ""
RETURN
    IF (
        AG IN Spain_Shared;
        SWITCH (
P;
P1; "0.4";
P2; "0.8";
P3; "3";
P4; "3";
PBlank; "3";
""
); "" )

Can you confirm this still works?

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

2 REPLIES 2
OwenAuger
Super User
Super User

Hi Albin,

 

This is a calculated column by the looks of it.

I would suggest declaring some variables and using the SWITCH function.

 

Here is one way of doing it where I have stored almost every column value and constant in a variable. The SWITCH function replaces most of the nested IFs. I have also simplified the expression of the logical tests.

 

SLA FORM OTC =
VAR P = 'SNOW(sn_sm_finance_request)'[priority]
VAR AG = 'SNOW(sn_sm_finance_request)'[assignment_group]
VAR Spain = "FSM OTC Front Office Spain"
VAR Shared = "FSM OTC Shared Service Center"
VAR Spain_Shared = { Spain; Shared }
VAR P1 = "1 - Critical"
VAR P2 = "2 - High"
VAR P3 = "3 - Moderate"
VAR P4 = "4 - Low"
VAR PBlank = ""
RETURN
    IF (
        AG IN Spain_Shared;
        SWITCH (
P;
P1; "0.4";
P2; "0.8";
P3; "3";
P4; "3";
PBlank; "3";
""
); "" )

Can you confirm this still works?

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn
Anonymous
Not applicable

Hi, 

 

Thank you very much!

It work great.

 

Regards 

Albin

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.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.

March Power BI Update Carousel

Power BI Community Update - March 2026

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