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.
I have the following situation:
Product_Code (columnt of text type)
234567
765432
87345
3587
12
1234678
I need to create a new column in power query with a fixed size of 10 chars and the contents above described, but filling the gaps with 0 on the left side of the field, like this:
0000234567
0000765432
0000087345
0000003587
0000000012
0001234678
Does anybody have a tip or direction in how to active it with M language in Power Query? Thanks!
Solved! Go to Solution.
In Power Query, with Text.PadStart( ).
Text.PadStart(Text.From([Product_Code]),10,"0")
I'm going something else too. Give me a second.
Edit -
This works nicely so you don't need to add an additional Custom Column:
= Table.ReplaceValue(Source, each[Product_Code], each Text.PadStart(Text.From([Product_Code]),10,"0"),Replacer.ReplaceValue,{"Product_Code"})
Proud to be a Super User!
In Power Query, with Text.PadStart( ).
Text.PadStart(Text.From([Product_Code]),10,"0")
I'm going something else too. Give me a second.
Edit -
This works nicely so you don't need to add an additional Custom Column:
= Table.ReplaceValue(Source, each[Product_Code], each Text.PadStart(Text.From([Product_Code]),10,"0"),Replacer.ReplaceValue,{"Product_Code"})
Proud to be a Super User!
Thanks @ChrisMendoza and @asad The text pad function works perfect in my case.
As I have some fileds with more than 10 chars I use the following:
if Text.Length([COD_PRODUTO]) < 10 then
Text.PadStart([COD_PRODUTO],10,"0") else
[COD_PRODUTO]
Thank you guys!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
110 | |
97 | |
78 | |
63 | |
55 |
User | Count |
---|---|
143 | |
109 | |
89 | |
84 | |
66 |