Text.PadStart
Text function · By Tahir Nas · Examples run in our simulator · Published · Updated
Pads text on the left to a given length.
When to use it
Use it to restore leading zeros on codes, account numbers or ZIP codes that were read as numbers, so they match the other system's format.
Syntax
Text.PadStart(text as nullable text, count as number, optional character as nullable text) as nullable textParameters
- character
- Pad character (default space).
Returns
The padded text.
Example
Text.PadStart("104", 6, "0")Result
000104
Example: rebuild a code from a number
Convert the number to text, then pad to the fixed width.
Text.PadStart(Text.From(42), 5, "0")Result
00042
Both results are produced by the Power Query Exercises simulator, an independent implementation of a documented subset of M, and checked on every build.
Good to know
- Text longer than count is returned unchanged.
Common mistakes
- Padding a number directly: convert with Text.From first.
- Padding to a width shorter than some values, which leaves those unchanged.
Exercises that use Text.PadStart
Learn more
- Split columns and extract text by delimiter lesson
- Power Query text functions cheat sheet (tested) guide
Related functions
Official documentation: Text.PadStart on Microsoft Learn.