How to Add Leading Zeros to Dates in Excel Power Query
Question details
The user needs to add leading zeros to single-digit month and day values in Power Query to properly construct a standardized YYYYMMDD date format.

- Product
- Excel Power Query
- Device & OS
- not provided
- Scenario
- Splitting date components into separate year, month, and day columns, or attempting to concatenate them into a custom string where months and days must uniformly display two digits.
- Observed behavior
- Month and day values extracted as single digits (e.g., '1' for January) lack the necessary leading zeros required for standard two-digit date formats.
Ensure your target columns are formatted as Text rather than Whole Numbers, as text-padding functions in Power Query will result in errors if applied to numeric data types.
Use the Text.PadStart Function
Applying the Text.PadStart function is the most reliable way to enforce a two-character length for month and day columns by padding single digits with a zero.
The Text.PadStart function requires three arguments: the text string to evaluate, the total desired character length, and the character to use for padding. This approach is ideal for separated day and month columns.
In the Power Query Editor, select your Month or Day column. Right-click the column header, select 'Change Type', and click 'Text'. Replace current conversions if prompted.
Navigate to the 'Add Column' tab on the top ribbon and select 'Custom Column'. A dialog box will appear.
In the Custom Column Formula box, type the formula: = Text.PadStart([YourColumnName], 2, "0") and click OK. This will generate a new column with leading zeros applied to single digits.
Convert to Date and Format via Custom Number Format
If your end goal is just displaying the date in a YYYYMMDD format inside your spreadsheet, handle the transformation using Excel formatting rather than Power Query text manipulation.
Use Date.ToText for Complete Dates
If your source data is already recognized as a unified date type in Power Query, you can instantly convert it into a padded text string without separating the components first.
Simplify Data Manipulation with WPS Office
If you find Microsoft Excel's Power Query formulas complex and time-consuming, consider switching to WPS Office. It offers an intuitive, lightweight spreadsheet application with advanced data handling and formatting tools that don't require programming knowledge.
- 1. Download and install: Visit the official WPS Office website and install the free software suite.
- 2. Open your data file: Launch WPS Spreadsheet and easily import your Excel or CSV data files.
- 3. Format data seamlessly: Select your date columns, right-click to choose 'Format Cells', and easily apply standard or custom formatting.

Frequently Asked Questions
Why does Text.PadStart result in an 'Expression.Error: We cannot convert the value to type Text'?
This error occurs because Text.PadStart only accepts text values, and your column is currently formatted as a whole number. You must either change the column type to Text or wrap your column reference in Text.From() within the formula.
Can I format dates as YYYYMMDD directly inside Power Query without converting to text?
No. Power Query treats a 'Date' data type uniformly and does not store display formats. To force a specific layout like YYYYMMDD inside Power Query, you must convert it to a Text string using Date.ToText. Otherwise, you format the date after loading it into the spreadsheet.
How do I combine the separate year, month, and day columns back together after adding leading zeros?
Once you have ensured the month and day columns are padded and formatted as text, you can combine them by adding a Custom Column and using the concatenation operator: = [Year] & [Month] & [Day].




