How to Format NDC Numbers in Excel Power Query
Question details
The user needs to convert numeric National Drug Code (NDC) data into a specific text format (00000-0000-00) to ensure leading zeros and hyphens are properly displayed.
- Product
- Excel Power Query
- Device & OS
- not provided
- Scenario
- Formatting raw numerical data into standardized NDC strings during the data transformation process in Power Query.
- Observed behavior
- The NDC values are stored as raw numbers, causing them to drop leading zeros and lack the necessary hyphens required for the final 11-digit format.
Ensure your dataset is loaded into the Power Query Editor and identify the exact name of the column containing your numeric NDC values before applying the custom format.
Use Number.ToText in a Custom Column
Create a custom column in Power Query using the Number.ToText function to force the numeric value into an 11-digit text string with hyphens.
Because Power Query treats raw numeric columns by stripping leading zeros, converting the number to text with a designated format mask is the most reliable way to enforce the standard NDC format.
In the Power Query Editor, navigate to the 'Add Column' tab on the top ribbon.
Click on 'Custom Column' to open the Custom Column dialog box.
Name your new column (e.g., 'Formatted NDC') and enter the following formula in the Custom column formula box: =Number.ToText([YourColumnName], "00000-0000-00"). Be sure to replace '[YourColumnName]' with the actual name of your NDC column.
Click 'OK' to create the column. The output will now display as text, preserving all leading zeros and applying the specified hyphenated pattern.
Need a lightweight and efficient alternative to Microsoft Excel?
If you often deal with complex data formatting and find Microsoft Office too heavy, expensive, or complex, try WPS Office. It provides powerful data processing tools, native spreadsheet text formatting, and is completely free to download.
- 1. Download the Installer: Visit the official WPS Office website and download the free installer for your operating system.
- 2. Install WPS Office: Run the setup file and follow the quick on-screen instructions to install the suite.
- 3. Open Your Spreadsheets: Launch WPS Spreadsheet and open your existing Excel files to easily format and manipulate your data.

Frequently Asked Questions
Why do my NDC numbers lose leading zeros in Excel and Power Query?
When numbers are stored in a standard numeric data type, spreadsheet programs automatically remove leading zeros because they hold no mathematical value. To preserve them, the data must be specifically formatted or converted to a text data type.
Can I format NDC numbers directly in standard Excel without Power Query?
Yes. You can use standard Excel Custom Formatting by selecting your cells, pressing Ctrl+1 to open Format Cells, choosing 'Custom', and typing '00000-0000-00'. Alternatively, you can use the formula =TEXT(A2, "00000-0000-00").
What does the Number.ToText function do?
Number.ToText is a Power Query M function that converts a numeric value into a text string. By adding a format string like "00000-0000-00" as the second argument, you can instruct it to pad the number with zeros and insert specific characters like hyphens.




