In this Power BI article, we will see how to remove leading zeros in Power BI using power query with different examples.
Remove leading zeros in Power BI
- Remove leading zeros used to remove the leading zero values in front of digits in Power BI, we use the Power Query editor trim function to remove the leading zeros in Power Bi.
- For example, In the below screenshot, you can see the Leading Zero column will be considered as an input column (like 01,02,03, etc.) and the Remove leading Zero columns (1,2,3, etc.) will be the expected output column after removing the leading zero values.
Remove leading zeros in Power BI using Power Query
Let us see how to remove leading zeros using the Power Query editor in Power BI,
In this example, we will use the products ordered table data, you can download it from here and use it in the Power Bi.
Example 1:
- Open the Power Bi desktop and load the Products Ordered data table by using the get data option.
- Then Select the transform data option under the home tab as highlighted below, and it will automatically redirect to the Power Query editor.
In the Power query editor, select the Add Column-> Add a Custom column as shown below:
In the Custom column window, use the below formula to trim the leading zero and click on the OK button.
= Text.TrimStart([Power Query],"0")
- In the below screenshot, you can see that the new custom column has displayed the values removed leading zeros.
- Click on the Close and Apply option, so that the changes will be reflected on the Power Bi desktop.
= Table.AddColumn(#"Added Custom", "Remove leading Zero", each Text.TrimStart([Power Query],"0"))
In the below screenshot, you can see that the removed leading zero column displays the expected output in the Power Bi data view.
This is how to remove leading zeros using the Power Query editor in Power BI.
Example 2:
We will see another example to remove leading zeros in Power Bi using the Power Query editor.
In this example, we will use the below-mentioned data table, and we will remove the leading zeros for the real zipcode column.
- In the same way load the Products Ordered data table by using the get data option.
- Then Select the transform data option under the home tab, and it will automatically redirect to the Power Query editor.
- In the Power query editor, select the Add Column-> Add a Custom column. In the Custom column window, use the below-mentioned formula to trim the leading zero and click on the OK button as shown below:
Text.TrimStart([Real Zip Code],"0")
- In the below screenshot, you can see that the new custom column has displayed the values removed leading zeros.
- Click on the Close and Apply option, so that the changes will be reflected on the Power Bi desktop.
= Table.AddColumn(#"Added Custom", "Remove leading zeros", each Text.TrimStart([Real Zip Code],"0"))
In the below screenshot, you can see that the removed leading zero column displays the expected output in the Power Bi data view.
This is how to remove leading zeros using the Power Query editor in Power BI.
This Power BI article explained how to remove leading zeros in Power BI using the Power Query editor in Power BI with different examples.
You may like the following power bi tutorials:
- Power BI Add Leading Zero to Month
- Power BI cross filter direction
- How to create a relationship in power bi without unique values
- How to remove Date Hierarchy in Power BI
- Power BI Zip Code Starting With 0
- How to implement row level security (RLS) in Power BI
I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com