cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Chris2016
Helper I
Helper I

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 II
Resolver II

@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 I
Helper I

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 I
Helper I

I also found a way to do it in DAX:

 

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

@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
Carousel_PBI_Wave1

2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

BizApps LATAM 2023

Business Application LATAM Summit 2023

Join the biggest FREE Business Applications Event in LATAM this February.

Power Platform Bootcamp

Global Power Platform Bootcamp

In this bootcamp we will deep-dive into Microsoft’s Power Platform stack with hands-on sessions and labs, delivered to you by experts and community leaders.

Top Solution Authors
Top Kudoed Authors