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
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
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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