Are Zip Codes missing a zero in the front digit in Power BI? Don’t worry, This Power Bi tutorial will help you how to work with Zip Code Starting With 0 in Power BI. Also will cover the below topics:
- Power BI Zip Code starting with 0
- Power BI Zip Code leading zero
Power BI Zip Code starting with 0
- It is possible to start a Zip Code with zero in the Power Bi.
- For example, In the below screenshot, you can see the Ship to Zip Code column will be considered as an input column (like 595, 9625, etc.) and the Real Zip Code column (00595, 09625, etc.) will be the expected output column after adding the leading zero values.
So Let us see how we can display the zip code starting with 0 in Power Bi.
In this example we will use the Products Ordered Excel Spreadsheet as a data source, you can download and use it in the Power Bi report.
In the below screenshot of the Excel sheet, the Ship to Zip Column is of a number data type that is not accepting the Zip Code starting with 0 in Power BI.
To add a zero in front of the Zip Codes in Power BI, follow the instructions below:
- Log in to the Power Bi desktop and load the data into it, Once the data has been loaded click on the new column under the modeling tab and use the below DAX formula:
- The below-mentioned formula helps us to transform the multiple zip code values, for example, if the length of the zip code value is 5 then it will display the same 5 zip code values, else the length of the zip code is 4 then it will add a leading zero with the zip code.
- If the length of the zip code is 3 then it will add two leading zeros with the zip code in the new column.
RealZipCode =
SWITCH(
TRUE(),
LEN('Products Ordered'[Ship to Zip Code]) = 5, 'Products Ordered'[Ship to Zip Code],
LEN('Products Ordered'[Ship to Zip Code]) = 4, "0" & 'Products Ordered'[Ship to Zip Code],
LEN('Products Ordered'[Ship to Zip Code]) = 3, "00" & 'Products Ordered'[Ship to Zip Code]
)
Where,
- RealZipCode = New Column Name
- Products Ordered = Table Name
- Ship to Zip Code = Existing column name
In the below screenshot, you can see that the new column has added the leading zero’s to the Zip code based on the condition applied.
This is how we can display the zip code starting with 0 in Power Bi.
Power BI Zip Code leading zero
- It is possible to start a Zip Code with zero in Power Bi.
- For example, In the below screenshot, you can see the Ship to Zip Code column will be considered as an input column (like 9625, etc.) and the Real Zip Code column (09625, etc.) will be the expected output column after adding the leading zero values.
So let us see how we can add a leading zero for the single Zip Code using the Power Bi Dax in Power BI.
In the example, we will see how to add a leading zero only for the selected or particular zip code value as highlighted below:
To achieve it follow the below steps:
- Log in to the Power Bi desktop and load the data into it, Once the data has been loaded click on the new column under the modeling tab and use the below DAX formula:
- The below-mentioned formula helps us to transform the selected zip code values, for example, if the length of the zip code is 4 then it will add a leading zero with the zip code in the new column.
RealZipCode =
IF( LEN( [Ship to Zip Code] ) = 4,
CONCATENATE( "0", [Ship to Zip Code] ),
[Ship to Zip Code]
)
Where,
- RealZipCode = New Column Name
- Ship to Zip Code = Existing column name
In the below screenshot, you can see that the new column has added the leading zero’s to the specified Zip code based on the condition applied.
This is how to add a leading zero for the single Zip Code using the Power Bi Dax in Power BI.
In this Power Bi tutorial, we have learned how to work with Zip Code Starting With 0 in Power BI. Also, we covered the below topics:
- Power BI Zip Code starting with 0
- Power BI Zip Code leading zero
You may also like the below Power BI tutorials:
- How to Remove Leading Zeros in Power BI
- Power BI Add Leading Zero to Month
- Power BI Convert Number to Text
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