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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Anonymous
Not applicable

Nested IF Question?

Hello All, I need some assistance with writing Nested If statement, I am trying to create a new column with the following if statement.

 

IF      [Category] = "Martial Arts "         THEN

IF          [Sub Category] = "Boxing"                        THEN "Boxing "

                ELSEIF  [Sub Category] = "Karate"                        THEN "Karate"

    END

 

ELSEIF  [Category] = "Sports"                              THEN "Sports"

ELSEIF  [Category] = "Winter Sports"        THEN

    IF          [Sub Category] = "Snowboarding"              THEN "Snowboarding"

    ELSEIF      [Sub Category] = "Skiing"            THEN "Skiing"

    END

 

 

I tried using Switch function and had no luck, does anyone has any suggestions?

 

Thank you

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

I think SWITCH is a good idea.

 

SWITCH (
    TRUE (),
    [Category] = "Martial Arts " && [Sub Category] = "Boxing", "Boxing",
    [Category] = "Martial Arts " && [Sub Category] = "Karate", "Karate",
    [Category] = "Sports", "Sports",
    [Category] = "Winter Sports" && [Sub Category] = "Snowboarding", "Snowboarding",
    [Category] = "Winter Sports" && [Sub Category] = "Skiing", "Skiing"
)

View solution in original post

2 REPLIES 2
AlexisOlson
Super User
Super User

I think SWITCH is a good idea.

 

SWITCH (
    TRUE (),
    [Category] = "Martial Arts " && [Sub Category] = "Boxing", "Boxing",
    [Category] = "Martial Arts " && [Sub Category] = "Karate", "Karate",
    [Category] = "Sports", "Sports",
    [Category] = "Winter Sports" && [Sub Category] = "Snowboarding", "Snowboarding",
    [Category] = "Winter Sports" && [Sub Category] = "Skiing", "Skiing"
)
Samarth_18
Community Champion
Community Champion

Hi @Anonymous ,

 

You can use below code:-

Measure =
IF (
    [Category] = "Martial Arts ",
    IF (
        [Sub Category] = "Boxing",
        "Boxing",
        IF (
            [Sub Category] = "Karate",
            "Karate",
            IF (
                [Category] = "Sports",
                "Sports",
                IF (
                    [Category] = "Winter Sports",
                    IF (
                        [Sub Category] = "Snowboarding",
                        "Snowboarding",
                        IF ( [Sub Category] = "Skiing", "Skiing" )
                    )
                )
            )
        )
    )
)

 

Thanks,

Samarth

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

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.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

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

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.