How to Remove Leading Zeros in Power BI

I was working on a Power BI report, and I noticed that some columns, like Employee ID, Customer Code, or Product Number, were stored as text and had leading zeros, for example, 000123.

When I use this column in a report and try to sort or filter the data, I am not getting the correct results. In most cases, I don’t need these extra zeros and want the values to appear in a clean format.

Power BI does not provide a direct option to remove leading zeros, but we can handle this easily using Power Query or DAX, depending on the requirement.

In this tutorial, I will show you different ways to remove leading zeros in Power BI.

Remove Leading Zeros in Power BI using Power Query

Now I will show you how to remove leading zeros in Power BI using Power Query and the Trim function.

For example, I want the Leading Zero column to be the input column and have values like 01, 02, 03, etc. After removing the leading zeros, the Remove Leading Zero column shows the final result with values like 1, 2, 3.

Remove leading zeros in Power BI

Here, I will use the data from the ordered products table.

To do this, follow the steps below:

  1. Open Power BI Desktop and load the Products Ordered table using the Get Data option.
  2. Then select the Transform Data option from the Home tab. This will automatically open the Power Query Editor.
Remove leading zeros in Power BI
  1. In the Power Query Editor, go to the Add Column tab and select Custom Column, as shown below.
Example to convert number to text with leading zeros in Power BI
  1. In the Custom Column window, enter the formula below to remove the leading zeros, and then click OK.
= Text.TrimStart([Power Query],"0")
Remove leading zeros in Power BI example
  1. Now you can see that the new custom column displays the values without leading zeros.
Remove leading zeros in the Power BI

This is how to remove leading zeros using the Power Query editor in Power BI.

Remove Leading Zeros from Text Columns in Power BI (Power Query)

Now, let us look at another example to remove leading zeros in Power BI using the Power Query Editor. In this example, the data table shown below is used, and the leading zeros are removed from the Zipcode column.

Remove leading zeros Power BI dax

Follow the steps below:

  1. Open the Power BI Desktop and load the Products Ordered data table using the Get Data option. Then select the Transform Data option under the Home tab.
  2. In the Power Query Editor, go to the Add Column tab and select Custom Column.
dax remove leading zeros in Power BI
  1. In the Custom column window, use the following formula to trim the leading zero and click on the OK button as shown below:
Text.TrimStart([Real Zip Code],"0")
Remove leading zeros from text string Power BI
  1. Then you can see that the new custom column displays the values without leading zeros.
Remove leading zeros in text field Power BI

This is how to remove leading zeros using the Power Query editor in Power BI.

Remove Leading Zeros in Power BI using Convert Data Type

In this scenario, leading zeros are removed by changing the data type in Power BI. When a column is converted from Text to Whole Number, Power BI automatically removes the leading zeros.

power query remove leading zeros

Here, I want to remove the leading zero from the Quantity column.

To do this, follow the steps below:

  1. In Power BI Desktop, load your data, then go to the Table view.
power query trim leading zeros
  1. Select the table and then select the column from which you want to remove the leading zeros (in this case, Quantity). Under the Column tools tab, expand the Data type dropdown and select Whole number.
remove leading zeros in power query
  1. Then a pop-up will show where you click Yes.
remove leading zeros power query

Next, you can see the leading zero removed in the quantity column by changing the data type in Power BI.

Remove Leading Zeros Using Power BI DAX

In this scenario, leading zeros are removed by using a DAX formula. A new calculated column is created, and the DAX expression converts the text value into a number, which automatically removes the leading zeros.

For this example, I will use the same case where we remove the leading zero in the Order ID column.

Follow the steps below:

  1. In Power BI Desktop, go to table view, under the Home tab, click New column.
power bi remove leading zeros
  1. Enter the following DAX formula:
Remove Leading Zero = VALUE('ProductsOrdered'[Order ID])
remove leading zeros in power bi
  1. The new column will display values like 1, 2, 3 instead of 001, 002, 003, and the leading zeros will be removed.
Remove Leading Zeros Using Power BI DAX

Note:

This method works only when the column contains numeric values. If the column has text or special characters, this formula may return an error.

In this tutorial, I covered how to remove leading zeros in Power BI. I explained how to remove leading zeros using Power Query with the Trim function, changing the data type from Text to Whole Number, and a DAX formula.

You may like the following Power BI tutorials:

Power Apps functions free pdf

30 Power Apps Functions

This free guide walks you through the 30 most-used Power Apps functions with real business examples, exact syntax, and results you can see.

Download User registration canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App