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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
ovetteabejuela
Impactful Individual
Impactful Individual

Power Query | Replacing Text Recommendation (Wildcard/RegEx)?

Hi,

I have a very simple problem, so Im still working on names... full names unfortunately there are some inconsistencies that I wanted to fix.

 

For example there's a
      <Last Name><comma><First Name>
and theen there's a
      <Last Name><comma><space><First Name>
and I wanted everythin in the latter format, <Last Name><comma><space><First Name>.

 

What I'm doing is
Replace <Last Name><comma><First Name> with
             <Last Name><comma><space><First Name>
great but that would cause the other entries to turn into
            <Last Name><comma><space><space><First Name>
so I add an extra step to
Replace <Last Name><comma><space><space><First Name> with, or back to
             <Last Name><comma><space><First Name>

so that's two steps. The question, is there a better way of doing this, a one-liner?

1 ACCEPTED SOLUTION
MarcelBeug
Community Champion
Community Champion

Apart from combining multiple steps in 1 line, I don't see any way.

 

2 Alternatives:

 

Table.AddColumn(Source, "Custom", each Text.Combine(List.Transform(Text.Split([Name],","), Text.Trim),", "))

or

Table.AddColumn(Source, "Custom", each Text.Replace(Text.Replace([Name],",",", "),",  ",", "))
Specializing in Power Query Formula Language (M)

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

 

Try this

 

  1. Select that column heading and right click > Replace
  2. Find for space and click on Replace All
  3. Select that column heading and right click > Replace
  4. Find for , and in the Replace with box, type , i.e. comma and space
  5. Click on Replace All

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur that are still 2 steps ... Smiley Wink

Specializing in Power Query Formula Language (M)

@Ashish_Mathur, thanks but I think that was my path already.

 

@MarcelBeug, thanks for that atleast that's a oneliner. so with you suggesting that I'd presume PQ doesn't have anything like Regular Expressions which I think could address this gracefully. Anyway I'm happy with your suggestion aleady.

Well, I think my first alternative is pretty graceful (M-style).  Smiley LOL

 

Anyhow, what regular expression would you have in mind?

E.g. in Word, I can't think of any way to replace "," or ", " by ", " in 1 step.

Specializing in Power Query Formula Language (M)
MarcelBeug
Community Champion
Community Champion

Apart from combining multiple steps in 1 line, I don't see any way.

 

2 Alternatives:

 

Table.AddColumn(Source, "Custom", each Text.Combine(List.Transform(Text.Split([Name],","), Text.Trim),", "))

or

Table.AddColumn(Source, "Custom", each Text.Replace(Text.Replace([Name],",",", "),",  ",", "))
Specializing in Power Query Formula Language (M)

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.