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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Chris2016
Helper II
Helper II

Remove symbol at the beginning of a column if it exists

Hello,

 

I need some help removing a symbol ("-") if it exists in the beginning of a column value, but keep it if it exists elswhere in the value (not at the beginning).

E.g.:

ColumnResult Column
-alexalex
johnjohn
a-alberta-albert
-dandan
b-judyb-judy


Any thoughts? 

Thanks!

2 ACCEPTED SOLUTIONS
Uspace87
Resolver III
Resolver III

@Chris2016 

 

 

I have used a series of steps in "Power query".

please find below the query code with all the steps:

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W0s1LzE1VitWJVipJLS7RLUBiFujqKsXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Test = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Test", type text}}),
#"Inserted First Characters" = Table.AddColumn(#"Changed Type", "First Characters", each Text.Start([Test], 1), type text),
#"Extracted Text Range" = Table.TransformColumns(#"Inserted First Characters", {{"Test", each Text.Middle(_, 1, 10000000), type text}}),
#"Replaced Value" = Table.ReplaceValue(#"Extracted Text Range","-","",Replacer.ReplaceText,{"First Characters"}),
#"Merged Columns" = Table.CombineColumns(#"Replaced Value",{"First Characters", "Test"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Merged")
in
#"Merged Columns"

View solution in original post

Chris2016
Helper II
Helper II

I also found a way to do it in DAX:

 

CleanUp = IF(LEFT([Column], 1)="-", MID([Column], 2,LEN([Column])),[Column])

View solution in original post

5 REPLIES 5
Chris2016
Helper II
Helper II

I also found a way to do it in DAX:

 

CleanUp = IF(LEFT([Column], 1)="-", MID([Column], 2,LEN([Column])),[Column])
Uspace87
Resolver III
Resolver III

@Chris2016 

 

 

I have used a series of steps in "Power query".

please find below the query code with all the steps:

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W0s1LzE1VitWJVipJLS7RLUBiFujqKsXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Test = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Test", type text}}),
#"Inserted First Characters" = Table.AddColumn(#"Changed Type", "First Characters", each Text.Start([Test], 1), type text),
#"Extracted Text Range" = Table.TransformColumns(#"Inserted First Characters", {{"Test", each Text.Middle(_, 1, 10000000), type text}}),
#"Replaced Value" = Table.ReplaceValue(#"Extracted Text Range","-","",Replacer.ReplaceText,{"First Characters"}),
#"Merged Columns" = Table.CombineColumns(#"Replaced Value",{"First Characters", "Test"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Merged")
in
#"Merged Columns"

Hi, @Uspace87,

Thanks a lot, this helps. Can you let me know how you added the "Inserted First Characters" step?

Best regards!

@Chris2016 

 

You need yo use "Add column" and then "Extract first Char"

Thank you!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors