cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Post Partisan
Post Partisan

Adding Leading Zeros in Power Query

How can I add leading zeros in Power Query only if a certain criteria is met. For example, I have a column where the number of digits can range from 10-13, but all of them need to be 13 digits. So if the field contains 10 digits, I would need to add 3 leading zeros. If it contained 11 digits, I would need to add 2 leading zeros, etc. 

 

Thanks!

1 ACCEPTED SOLUTION

@PowerBI123456 , then you reference a specific column in the formula

Table.AddColumn(#"Previous step", "Leading 0s", each Number.ToText([number column], Text.Repeat("0",13)))

View solution in original post

5 REPLIES 5
Super User IV
Super User IV

If you need to keep them as number format, you can also use Custom Format Strings after you load the data.

Use custom format strings in Power BI Desktop - Power BI | Microsoft Docs

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Super User III
Super User III

Hi, @PowerBI123456 , you might want to follow this pattern to format all numbers,

 

Number.ToText(1234567890, Text.Repeat("0",13))

Screenshot 2020-12-16 002532.png

 

 

@CNENFRNL Thanks, what if I want to refer to a specific column?

@PowerBI123456 , then you reference a specific column in the formula

Table.AddColumn(#"Previous step", "Leading 0s", each Number.ToText([number column], Text.Repeat("0",13)))

View solution in original post

@CNENFRNL  thank you!

Helpful resources

Announcements
secondImage

Congratulations!

We are excited to announce the Power BI Super Users!

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors