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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. 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
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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