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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

Reply
balar2007
Regular Visitor

SWITCH or IF

I need to transform a case statement which i have written in spotfire to Power Bi

case
WHEN [Formula]~="EBOB" THEN "MOGAS"
WHEN [Formula]~="G01" THEN "GASOIL"
WHEN [Formula]~="G50" THEN "GASOIL"

WHEN [Grade]~="DAOWA" THEN "FO"

WHEN ([Formula]~="BOB10ARGM") And ([Grade]~="M5859") THEN "MOGAS"
WHEN ([Formula]~="FRONTLINEICELS") And ([Grade]~="HYWAX") THEN "FO"

WHEN ([Client]~="MFPERNIS") And ([Formula]~="BIPEB") THEN "HEDGES"

ELSE [Formula]

 

Since multiple columns from a table is involved how do I write a DAX expression using SWITCH.  If not Switch what is the better way

Help me out

7 REPLIES 7
Anonymous
Not applicable

Hi @balar2007 ,

Could you tell me if your problem has been solved?
If it is, kindly Accept it as the solution. More people will benefit from it.
Or you are still confused about it, please provide me with more details about your table and your problem or share me with your pbix file from your Onedrive for Business.


Best Regards,
Stephen Tao

PhilipTreacy
Super User
Super User

Hi @balar2007 

To look for the string EBOB in [Formula] modify the line to this

CONTAINSSTRING( [Formula], "EBOB" ), "MOGAS"

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Anonymous
Not applicable

Hi @balar2007 ,

 

As @amitchandak  said,  Switch True is a good idea.

 

In addititon, you can also try IF.

 

Formula =
IF (
    [Formula] = "EBOB",
    "MOGAS",
    IF (
        [Formula] = "G01",
        "GASOIL",
        IF (
            [Formula] = "G50",
            "GASOIL",
            IF (
                [Grade] = "DAOWA",
                "FO",
                IF (
                    [Formula] = "BOB10ARGM"
                        && [Grade] = "M5859",
                    "MOGAS",
                    IF (
                        [Formula] = "FRONTLINEICELS"
                            && [Grade] = "HYWAX",
                        "FO",
                        IF ( [Client] = "MFPERNIS" && [Formula] = "BIPEB", "HEDGES", [Formula] )
                    )
                )
            )
        )
    )
)

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

amitchandak
Super User
Super User

@balar2007 , Switch True will help in this case

 

Switch( True() ,
, [Formula]="EBOB" , "MOGAS"
, [Formula]="G01" , "GASOIL"
, [Formula]="G50" , "GASOIL"

, [Grade]="DAOWA" , "FO"

, ([Formula]="BOB10ARGM") && ([Grade]~="M5859") , "MOGAS"
, ([Formula]="FRONTLINEICELS") && ([Grade]~="HYWAX") , "FO"

, ([Client]="MFPERNIS") && ([Formula]~="BIPEB") , "HEDGES"

, [Formula]
)

 

refer Video: https://www.youtube.com/watch?v=gelJWktlR80

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hello Amit

Quick clarification, how do i manipulate it in case if I have to use contain in the formula you gave. For example Formula contains EBOB then equal to "MOGAS". 

Anonymous
Not applicable

Hi @balar2007 ,

 

Please kindly refer to the below link which has similar issue:

 

https://community.powerbi.com/t5/Desktop/Find-if-value-contains-anything-from-another-column/td-p/13...

 

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

mahoneypat
Microsoft Employee
Microsoft Employee

Switch is the way to go.  Here is an example with your code, but not clear if you are doing a column or measure.  This assumes [Formula] is a measure.  Note the Formula is first calculated in a variable so it is not recalculated multiple times.

 

Switch Example =
VAR vFormula = [Formula]
RETURN
    SWITCH (
        vFormula,
        "EBOB""MOGAS",
        "G01""GASOIL",
        "G50""GASOIL",
        vFormula
    )

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


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.