Forum Discussion
Remove leading Zero's in Query
- 8 years ago
You can just choose Transform - Foormat - Trim and then adjust the generated code to have zeroes trimmed from the start.
let Source = #table({"String"},List.Zip({{"000MarcelBeug","000Ol"}})), #"Trimmed Text" = Table.TransformColumns(Source,{{"String", each Text.TrimStart(_,"0")}}) in #"Trimmed Text"
Is it possible? Anyone?
You can just choose Transform - Foormat - Trim and then adjust the generated code to have zeroes trimmed from the start.
let
Source = #table({"String"},List.Zip({{"000MarcelBeug","000Ol"}})),
#"Trimmed Text" = Table.TransformColumns(Source,{{"String", each Text.TrimStart(_,"0")}})
in
#"Trimmed Text"- edhans8 years agoCommunity Champion
The proposed solution works, but sadly cannot be sent to the server to handle in a SQL statement (query folding). I've not figured out a way to do this without braking query folding....
- Anonymous8 years agoNot applicable
Worked perfectly. Thanks for your help MarcelBeug
- Shelley8 years agoPost Prodigy
Hi There, I'm wondering if you'd be so kind as to help me too. I am also trying to remove leading zeros, but not every record has them. Some records are alphanumeric. I have tried using your code below like this:
let
Source = Sql.Database("CSMDataService.cloudapp.net", "CSM_Master"),
dbo_RepairTransaction = Source{[Schema="dbo",Item="RepairTransaction"]}[Data],
#"Trimmed Text" = Table.TransformColumns(dbo_RepairTransaction,{{"Contract_Number", each Text.TrimStart(_, "0")}}),
#"Inserted Merged Column" = Table.AddColumn(dbo_RepairTransaction, "Key", each Text.Combine({[End_User_Key], [Contract_Number]}, "="), type text),
#"Renamed Columns" = Table.RenameColumns(#"Inserted Merged Column",{{"Key", "%BPIDContractKey"}})
in
#"Renamed Columns"It appears to run without any errors or messages, but it also doesn't work.
Thanks in advance for any advice.
- MarcelBeug8 years agoCommunity Champion
It doesn't work because you forgot to adjust the step reference in the next step.
let Source = Sql.Database("CSMDataService.cloudapp.net", "CSM_Master"), dbo_RepairTransaction = Source{[Schema="dbo",Item="RepairTransaction"]}[Data], #"Trimmed Text" = Table.TransformColumns(dbo_RepairTransaction,{{"Contract_Number", each Text.TrimStart(_, "0")}}), #"Inserted Merged Column" = Table.AddColumn(#"Trimmed Text", "Key", each Text.Combine({[End_User_Key], [Contract_Number]}, "="), type text), #"Renamed Columns" = Table.RenameColumns(#"Inserted Merged Column",{{"Key", "%BPIDContractKey"}}) in #"Renamed Columns"
- banks3346 years agoFrequent Visitor
This returned for me a table with two values... one being the trimmed value and one being blank...
I had to modify it as follows:
let Source = #table({"String"},{{[DRNum]}}), #"Trimmed Text" = Table.TransformColumns(Source,{{"String", each Text.TrimStart(_,"0")}}) in #"Trimmed Tex- JaydipPatel816 years agoFrequent Visitor
Use Columns from example if you have a column with Numbers, texts, and numbers with leading zeros.
- Anonymous2 years agoNot applicable
This worked for me perfectly and was the easiest solution. Thank you