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
mtrevisiol
Helper V
Helper V

Concatenate a string and a column value in Power Query (M)

Hi everyone.

I'm trying to modify some data using M in Power Query.

This is my table:

 

mtrevisiol_0-1638876137554.png

 

I'd like to modify the "ActiveUsers" column by replacing null values with the corresponding "OpId" value, so this is the formula I wrote:

mtrevisiol_1-1638876242806.png

However, my intent is to replace null values mantaining the same structure of the other values in ActiveUsers, so I would like to put a "u" at the beginning and at the end of the numbers (i.e. 41 becomes "u41u", 82 becomes "u82" and so on).

 

How can I do it? Many thanks.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @mtrevisiol ,

Please have a try.

= Table.ReplaceValue(#"Changed Type",null, each "u"&Text.From([Opld])&"u",Replacer.ReplaceValue,{"ActiveUsers"})

11.PNG

 

22.jpeg

 

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Hi @mtrevisiol ,

Please have a try.

= Table.ReplaceValue(#"Changed Type",null, each "u"&Text.From([Opld])&"u",Replacer.ReplaceValue,{"ActiveUsers"})

11.PNG

 

22.jpeg

 

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Trying to do the same thing in 2023 and this solved my problem. Thanks!

Thank you, @Anonymous , TextForm function was fundamental!

Mikelytics
Resident Rockstar
Resident Rockstar

Hi @mtrevisiol ,

 

Please try the following

 

if [ActiveUsers] = null then "u" & Number.ToText([OpId]) else [ActiveUsers]

 

The NUmber.ToText is only needed because you want to concat a number and a string which is not possible so the number has to be converted into a string. you can also convert the numner into a string upfront then you do not need the Number.ToText formula

________________________

If this post helps, then please Accept it as the solution to help other community members find it more quickly

Click on the Thumbs-Up icon if you like this reply.

 

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

@Mikelytics 

replaced the line of code I wrote with:

 #"Change" = if [ActiveUsers] = null then "u" & Number.ToText([OpId]) else [ActiveUsers]

but I got

Expression.Error: An unknown identifier is present. Was the abbreviated [field] syntax used for _[field] outside an 'each' expression?

amitchandak
Super User
Super User

@mtrevisiol , Try something like

Text.Replace([ActiveUsers], null, "u" & Number.ToText([OptId]))

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak I replaced the line of code I wrote with:

#"Change" = Text.Replace([ActiveUsers], null, "u" & Number.ToText([OpId]))

but I got

Expression.Error: An unknown identifier is present. Was the abbreviated [field] syntax used for _[field] outside an 'each' expression?

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.