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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
JoeyF
Frequent Visitor

Nested IF OR Statement when creating a New Custom Column

I am trying to create a new Custom Column which is creating a new Category Name based on the text contained in the CATNAME column. 

Basically I want the Category Name to be "Roads" if the CATNAME contains either "Sign", "Kerb", "Path", or "Road" OR if the CATNAME contains "Drain" then I want it to be "Drainage". If it is none of these then the original CATNAME should be displayed.

I have tried the below but there seems to be an error at then in the 4th line. Have I got the logic incorrect?

 

JoeyF_0-1717021920843.png

Thank you.

 

1 ACCEPTED SOLUTION
kpost
Super User
Super User

Well, I'm much more familiar with DAX than Power Query. 

 

So here's how I'd do it as a calculated column.  But don't let this deter you from trying it your way, just throwing in one viable solution.

 

Custom Column = 
VAR catname = [CATNAME]
RETURN
SWITCH(
        TRUE(),
         CONTAINSSTRING(catname, "SIGN") || CONTAINSSTRING(catname, "KERB") || CONTAINSSTRING(catname, "PATH") || CONTAINSSTRING(catname, "ROAD"), "Roads",

         CONTAINSSTRING(catname, "DRAIN"), "Drainage",
         catname

)

 

Hopefully you can get some help with your column in Power Query, but if not this will work for you.

View solution in original post

2 REPLIES 2
Transform121
Helper I
Helper I

The issue is syntax.

You have more nestings created by open parenthesis than you do by closed. Count your open and closed parenthesis separately (using a stepping method) and you'll see where things are left open.

 

I've put a simple counting image below for parenthesis, but you're currently missing 5 closed parenthesis because of additional inserts. If you resolve this the token literal error should fix itself.

 

Transform121_0-1717025833555.png

 

Try something like this. It will nest all of the first options for roads into 1 group.

 

if (Text.Contains([CATNAME], "SIGN") or Text.Contains([CATNAME], "KERB") or Text.Contains([CATNAME], "PATH") or Text.Contains([CATNAME], "ROAD") then "ROADS") else if Text.Contains([CATNAME], "DRAIN"), "Drainage", else [CATNAME]

 

kpost
Super User
Super User

Well, I'm much more familiar with DAX than Power Query. 

 

So here's how I'd do it as a calculated column.  But don't let this deter you from trying it your way, just throwing in one viable solution.

 

Custom Column = 
VAR catname = [CATNAME]
RETURN
SWITCH(
        TRUE(),
         CONTAINSSTRING(catname, "SIGN") || CONTAINSSTRING(catname, "KERB") || CONTAINSSTRING(catname, "PATH") || CONTAINSSTRING(catname, "ROAD"), "Roads",

         CONTAINSSTRING(catname, "DRAIN"), "Drainage",
         catname

)

 

Hopefully you can get some help with your column in Power Query, but if not this will work for you.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

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