Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin 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.
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.
Solved! Go to Solution.
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- Try this steps, hope this should work.
Add a custom column:
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.
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
If it helps please mark my solution as accepted!
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
If it helps please mark my solution as accepted!
@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/
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
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:
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.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
17 | |
10 | |
8 | |
8 | |
7 |