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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
RasmusN532
Helper I
Helper I

Power BI - Power Query combining two columns and with IF statement help

Hi all!

I cant seem to get this to work, I´ve browsed some forum posts and thought this would work.

 

I want to create a column by combining two columns. However line_no can be null and if thats the case I want only the order_no to fill the new column. Else I want ordernumber & line no = 123 or 123_1,123_2 

 

This is how far I got:

IF[order_no]&"_"&[line_no] = "null" then [order_no] else [order_no]&"_"&[line_no]

 

I get the "Token Eof Expected" error. I am sure its something obvious but I havent worked in power query that much.

 

Thanks in advance.

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @RasmusN532 

If you're using the Custom Column dialog box, this code should work:

[order_no] & "_" & [line_no] ?? [order_no]

I've used the coalesce operator "??". If it is just line_no that can be null, then you could also write:

if [line_no] = null then [order_no] else [order_no] & "_" & [line_no]

OwenAuger_0-1712563909863.png

The M language is case-sensitive so keywords like "if" must be lowercase.

 

Does this help?

Regards

 


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

2 REPLIES 2
OwenAuger
Super User
Super User

Hi @RasmusN532 

If you're using the Custom Column dialog box, this code should work:

[order_no] & "_" & [line_no] ?? [order_no]

I've used the coalesce operator "??". If it is just line_no that can be null, then you could also write:

if [line_no] = null then [order_no] else [order_no] & "_" & [line_no]

OwenAuger_0-1712563909863.png

The M language is case-sensitive so keywords like "if" must be lowercase.

 

Does this help?

Regards

 


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

Thank you! It worked now 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

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.