Text.PadStart adds leading characters to a text value until it reaches a length you specify. In Power Query it is the standard way to turn numbers or short codes into fixed-width strings, such as padding "7" to "007". You do not need to install anything extra: the function is built into Power Query in Excel, Power BI Desktop, and Power Query Online, and you call it from the formula bar or the Add Column > Custom Column dialog.

What You'll Need

  • A Power Query editor session with a query already loaded — in Excel use Data > Get Data, and in Power BI use Transform data.
  • A text column, or a column you are willing to convert to text, because Text.PadStart expects a text value.
  • A clear target length in mind (for example, 3 characters for a store code, 10 for an account number).

Step-by-Step

  1. Open the Power Query editor. In Excel, select any cell in your table and go to Data > From Table/Range. In Power BI Desktop, select Transform data on the Home ribbon. Menu labels can differ slightly by version, device, and region, but these paths are the common ones.
  2. Select the query and column you want to pad. Click the column header so Power Query knows which field the new step should reference.
  3. Add a custom column. On the Add Column tab, choose Custom Column. This opens a dialog with a name field and a formula box.
  4. Enter the Text.PadStart formula. The syntax is Text.PadStart(text as nullable text, count as number, optional character as nullable text). A working example is Text.PadStart([StoreCode], 3, "0"). Replace [StoreCode] with your actual column name, 3 with your target length, and "0" with the character you want to repeat.
  5. Decide what to do when the value is already long enough. Text.PadStart never truncates. If the original text is longer than the count, it returns the original unchanged. If you need a strict fixed width, add a second step such as Text.Start(Text.PadStart([StoreCode], 3, "0"), 3).
  6. Handle numbers first. If your column is numeric, wrap it in Text.From, for example . Without that conversion you may get an error or an unexpected type.
  7. Choose the pad character carefully. The third argument is optional; if you leave it out, Power Query pads with a space. Use "0" for numeric-style codes, or another single character for fixed-width labels. Multi-character strings are not repeated as a pattern — only the first character is used.
  8. Click OK and review the new column. Power Query adds a step to the Applied Steps list. Check a few rows, especially short values, blank cells, and values that were already at or above the target length.
  9. Rename and set the type. Right-click the new column header to rename it, then use the data type icon to set it to Text. Padding with zeros produces text, not numbers, so do not set it to Whole Number or the leading zeros will disappear.
  10. Load the result. Use Home > Close & Load (Excel) or Home > Close & Apply (Power BI) to bring the padded column back into your workbook or model.

Common Mistakes

  • Padding a number column directly. Text.PadStart expects text. Convert with Text.From first, or you may see a type error or a result that drops the leading zeros when the column type is changed back to a number.
  • Expecting truncation. The function only adds characters. It will not shorten a value that is already longer than the target count.
  • Using a multi-character pad string. Passing something like "00" does not repeat the whole string; only the first character is used as the pad.
  • Forgetting nulls. A null value stays null. If you need a padded placeholder, wrap the call in a conditional such as if [Code] = null then "000" else Text.PadStart([Code], 3, "0").
  • Changing the column type back to Whole Number. Leading zeros are a text formatting feature. Once the column is numeric, the zeros are gone.

Tips

  • Use Text.PadStart for left padding and Text.PadEnd for right padding. They share the same argument order, so switching is easy.
  • Store the target length in a query parameter if you reuse the same width across several columns; you can then change it in one place.
  • Test with a small sample query first. Add a column with the original value next to the padded one so you can compare them side by side before loading.
  • If you are padding many columns, consider a custom function that accepts the column and length, then invoke it for each column instead of duplicating the formula.
  • Remember that the result is text. If downstream tools expect a number, convert explicitly and accept that leading zeros will not survive.

Troubleshooting

  • Error: We cannot convert a value of type Number to type Text. Wrap the column in Text.From, or change the column type to Text before adding the custom column.
  • Leading zeros disappear after loading. The column type was set to a number. Set it to Text in Power Query and keep it as text in the destination.
  • Nothing changes for some rows. Those values are already at or above the target length, or they are null. Check the original values and add a conditional if needed.
  • The pad character looks wrong. Confirm you passed a single character in quotes. If you omitted the third argument, the default is a space.
  • The formula bar shows an error but the dialog accepted it. Check column names for spaces or special characters; they may need to be referenced with the exact name shown in the query, and the step may need to be edited in the formula bar.
  • If that did not work, remove the custom column step, refresh the preview, and rebuild the formula one argument at a time — column, then count, then pad character — to see which part fails.

Frequently Asked Questions

Does Text.PadStart work in Excel and Power BI?

Yes. It is part of the Power Query M library and is available in Excel, Power BI Desktop, and Power Query Online. Menu labels can differ slightly between versions.

Can I pad with more than one character?

No. The optional pad argument uses only the first character of the string you supply. To repeat a pattern, build it with a custom formula instead.

What happens if the text is longer than the count?

The original text is returned unchanged. Text.PadStart does not truncate; combine it with Text.Start if you need a fixed width.

How do I pad a number column?

Convert it to text first with Text.From, then call Text.PadStart. Keep the resulting column typed as Text so the leading zeros remain visible.

What is the default pad character?

A space. If you want zeros, pass "0" as the third argument.

Does it handle null values?

Nulls remain null. Use a conditional expression if you want a padded placeholder for empty values.