Forum Discussion

PowerBI123456's avatar
PowerBI123456
Post Partisan
5 years ago
Solved

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!

  • CNENFRNL's avatar
    CNENFRNL
    5 years ago

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

5 Replies