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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
theapengelly
Frequent Visitor

Multiple IF statements on PowerBI Desktop

Hey,

 

Trying to create a custom column where it's value is dependent on [ID] and sometimes [Item] to determine a colour.

 

Any clue why the below is not working? I get an error message that the last 'then' is expecting a bracket?

 

= Table.AddColumn(#"Removed Spaces", "Custom", each if [ID] = "A" then "Red" else (if [ID] = "B" then "Red" else (if [ID] = "C" then "Red" else (if [ID] = "D" then "Red" else (if [ID] = "E" then "Blue" else (if [ID] = "F" then "Red" else (if [ID] = "G" then "Red" else (if([ID] = ("H") or [ID] = ("I") or [ID] = ("J") or [ID] = ("K") or [ID] = ("L")) then (if [Item] = "Socks" then "Green" else if([Item] = "Shirt" then "Yellow" else [ID]))))

 

Thank you in advance!

1 ACCEPTED SOLUTION
suparnababu8
Super User
Super User

Hi @theapengelly 

 

= Table.AddColumn(#"Removed Spaces", "Custom", each 
    if [ID] = "A" then "Red" 
    else if [ID] = "B" then "Red" 
    else if [ID] = "C" then "Red" 
    else if [ID] = "D" then "Red" 
    else if [ID] = "E" then "Blue" 
    else if [ID] = "F" then "Red" 
    else if [ID] = "G" then "Red" 
    else if [ID] = "H" or [ID] = "I" or [ID] = "J" or [ID] = "K" or [ID] = "L" then 
        if [Item] = "Socks" then "Green" 
        else if [Item] = "Shirt" then "Yellow" 
        else [ID]
    else null
)

Based on my understanding, I recreated this query. Pls use it and let me know if it works or not. 

View solution in original post

2 REPLIES 2
theapengelly
Frequent Visitor

Thanks so much, it worked!

suparnababu8
Super User
Super User

Hi @theapengelly 

 

= Table.AddColumn(#"Removed Spaces", "Custom", each 
    if [ID] = "A" then "Red" 
    else if [ID] = "B" then "Red" 
    else if [ID] = "C" then "Red" 
    else if [ID] = "D" then "Red" 
    else if [ID] = "E" then "Blue" 
    else if [ID] = "F" then "Red" 
    else if [ID] = "G" then "Red" 
    else if [ID] = "H" or [ID] = "I" or [ID] = "J" or [ID] = "K" or [ID] = "L" then 
        if [Item] = "Socks" then "Green" 
        else if [Item] = "Shirt" then "Yellow" 
        else [ID]
    else null
)

Based on my understanding, I recreated this query. Pls use it and let me know if it works or not. 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 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.

Top Solution Authors
Top Kudoed Authors