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
Datagulf
Responsive Resident
Responsive Resident

POWER QUERY - Ability to add a prefix to data that does not have the prefix

I am trying to clean a column that has some inconsistent data.

 

Current Column Desired Column
13B Prefix 13B
Prefix 15C Prefix 15C
Prefix 24D Prefix 24D
Prefix 23A Prefix 23A
15D Prefix 15D


How do I add the suffix to the column without the Prefix word. 

3 ACCEPTED SOLUTIONS
slorin
Super User
Super User

Hi

With Table.ReplaceValue

Table.ReplaceValue(
YourSource,
each [YourColumn],
each if Text.StartsWith([YourColumn],"Prefix") then [YourColumn] else "Prefix " & [YourColumn],
Replacer.ReplaceText,
{"YourColumn"}
)

Stéphane 

View solution in original post

@Datagulf- Try this steps, hope this should work.

Add a custom column:

  • Select the column that you want to modify.
  • Go to the "Add Column" tab in the Power Query Editor and click on the "Custom Column" button.
  • In the "Custom Column" dialog box, enter a name for the new column (e.g., "Column Test").
  • In the "Custom column formula" field, enter the following formula:
if Text.StartsWith([Current Column], "Prefix") then [Current Column] else "Prefix " & [Current Column]

Try following these steps, you should have a new column called "Column Test" that contains the data with the prefix added where necessary.

 

Let me know if this works for you. Thanks.

View solution in original post

Dhairya
Super User
Super User

Hey @Datagulf 
Please copy the following code in your advanced editor

let
Source = Table.FromRows(
Json.Document(
Binary.Decompress(
Binary.FromText(
"i45WMjR2UorViVYKKEpNy6xQMDR1RuYambigcI0dwVxDU6BwLAA=",
BinaryEncoding.Base64
),
Compression.Deflate
)
),
let
_t = ((type nullable text) meta [Serialized.Text = true])
in
type table [#"Current Column" = _t]
),
#"Changed Type" = Table.TransformColumnTypes(Source, {{"Current Column", type text}}),
#"Added Custom" = Table.AddColumn(
#"Changed Type",
"Desired Column",
each
if Text.StartsWith([Current Column], "Prefix") then
[Current Column]
else
"Prefix " & [Current Column]
)
in
#"Added Custom"

You will get the desired result as below

Dhairya_0-1687936916181.png

 



If it helps please mark my solution as accepted! 

View solution in original post

5 REPLIES 5
Dhairya
Super User
Super User

Hey @Datagulf 
Please copy the following code in your advanced editor

let
Source = Table.FromRows(
Json.Document(
Binary.Decompress(
Binary.FromText(
"i45WMjR2UorViVYKKEpNy6xQMDR1RuYambigcI0dwVxDU6BwLAA=",
BinaryEncoding.Base64
),
Compression.Deflate
)
),
let
_t = ((type nullable text) meta [Serialized.Text = true])
in
type table [#"Current Column" = _t]
),
#"Changed Type" = Table.TransformColumnTypes(Source, {{"Current Column", type text}}),
#"Added Custom" = Table.AddColumn(
#"Changed Type",
"Desired Column",
each
if Text.StartsWith([Current Column], "Prefix") then
[Current Column]
else
"Prefix " & [Current Column]
)
in
#"Added Custom"

You will get the desired result as below

Dhairya_0-1687936916181.png

 



If it helps please mark my solution as accepted! 

Manoj_Nair
Solution Supplier
Solution Supplier

@Datagulf, Hi Try this solution. In this formula, Text.StartsWith checks if the text starts with "Prefix ", and if it does, it keeps the text as it is. If it doesn't, Text.Combine adds "Prefix " to the beginning of the text.

 

if Text.StartsWith([Current Column], "Prefix ") 
    then [Current Column] 
    else Text.Combine({"Prefix ", [Current Column]}, "")

 

 

If this post helps to find solution would be happy if you could mark my post as a solution and give it a thumbs up

Best regards

Manoj Nair
Linkedin - https://www.linkedin.com/in/manoj-nair-%E2%98%81-344666104/

 

 

slorin
Super User
Super User

Hi

With Table.ReplaceValue

Table.ReplaceValue(
YourSource,
each [YourColumn],
each if Text.StartsWith([YourColumn],"Prefix") then [YourColumn] else "Prefix " & [YourColumn],
Replacer.ReplaceText,
{"YourColumn"}
)

Stéphane 

Datagulf
Responsive Resident
Responsive Resident

Hello . Thanks for the reply. Please help with the steps rather than the code...

@Datagulf- Try this steps, hope this should work.

Add a custom column:

  • Select the column that you want to modify.
  • Go to the "Add Column" tab in the Power Query Editor and click on the "Custom Column" button.
  • In the "Custom Column" dialog box, enter a name for the new column (e.g., "Column Test").
  • In the "Custom column formula" field, enter the following formula:
if Text.StartsWith([Current Column], "Prefix") then [Current Column] else "Prefix " & [Current Column]

Try following these steps, you should have a new column called "Column Test" that contains the data with the prefix added where necessary.

 

Let me know if this works for you. Thanks.

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.

Top Solution Authors