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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Netrelemo
Helper IV
Helper IV

How to identify and replace a specific string?

I want to replace all occurences of a particular string in a single column. 

 

The string must contain a "." in the second position. If it doesn;t or if it is null, I want to put in a "unknown" 

 

= Table.ReplaceValue(#"Sorted Rows", each not Text.Contains ([itemID],"."),"unknown",Replacer.ReplaceText,{"itemID"})

 

EXAMPLE

"X.NNNNNNNNNNNNNNN" is legitimate

"123456789" is not and should become "Unknown"

 

Attempts

= Table.TransformColumns(#"Changed Type", {{"Text", each if Text.ToList(_){1} = "." then _ else "Unknown", type text}})
Expression.Error: The column 'Text' of the table wasn't found.


=if(isnumber(mid(Data[ItemID],2,1)),"legitimate","Unknown")
Expression.SyntaxError: Token RightParen expected.

 

You can use https://docs.microsoft.com/en-us/powerquery-m/text-functions
Sure.... and when that doesn't work I come to this place

 

Column = if(mid('Table'[Column1],2,1)=".","legitimate","Unknown")

Expression.SyntaxError: Token Literal expected.

 

But this seems to have solved the problem: 

= Table.AddColumn(x, "Custom", each if Text.At([ColumnName], 1) = "." then "Legitimate" else "Not")

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Here is one way to do this.  

 

Select your column in the query editor and add a transform step, like add a prefix (you will replace so it doesn't matter what you choose).  This will generate a Table.TransformColumns step.  Once that is done, replace the "each" part with the "each part below

 

= Table.TransformColumns(#"Changed Type", {{"Text", each if Text.ToList(_){1} = "." then _ else "Unknown", type text}})

 

It converts the text string to a list and then checks if the 2nd one (counting starts at 0) is a ".".

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

5 REPLIES 5
ryan_mayu
Super User
Super User

@Netrelemo 

please try to create a column

Column = 

if(mid('Table'[Column1],2,1)=".","legitimate","Unknown")




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




amitchandak
Super User
Super User

@Netrelemo ,

You can use https://docs.microsoft.com/en-us/powerquery-m/text-functions

https://docs.microsoft.com/en-us/powerquery-m/text-at

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Ashish_Mathur
Super User
Super User

Hi,

Try this calculated column formula

=if(isnumber(mid(Data[ItemID],2,1)),"legitimate","Unknown")

Hope this helps.


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

Here is one way to do this.  

 

Select your column in the query editor and add a transform step, like add a prefix (you will replace so it doesn't matter what you choose).  This will generate a Table.TransformColumns step.  Once that is done, replace the "each" part with the "each part below

 

= Table.TransformColumns(#"Changed Type", {{"Text", each if Text.ToList(_){1} = "." then _ else "Unknown", type text}})

 

It converts the text string to a list and then checks if the 2nd one (counting starts at 0) is a ".".

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


ryan_mayu
Super User
Super User

@Netrelemo 

please provide the sample data and expected output.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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 Kudoed Authors