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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
getsmart
New Member

New column with contents and complete with 0 on left side

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!

1 ACCEPTED SOLUTION
ChrisMendoza
Resident Rockstar
Resident Rockstar

@getsmart -

 

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"})





Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



View solution in original post

3 REPLIES 3
asad
Frequent Visitor

Hey you could do this with Text.PadStart.

ChrisMendoza
Resident Rockstar
Resident Rockstar

@getsmart -

 

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"})





Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

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!

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors