In the Power BI tutorial, we will discuss what is Power BI Add Leading Zero to Month and how to work with Power BI Add Leading Zero to Month.
Also, We will see what are the various ways to add leading zero to a month in Power BI.
What is Add Leading Zero to Month in Power BI?
- The leading zero is added only to the numbers less than 10 so that the result is always a two-character text.
- For example, In the below screenshot, you can see the Month Number column will be considered as an input column (like 1, 2, 3, etc.) and the Direct Query column (01, 02, 03, etc.) will be the expected output column after adding the leading zero values.
Power BI Add Leading Zero to Month
Here we will see how to add Leading Zero to Month in Power BI.
In this example, we will use the Products ordered data table to add the leading zero to a month in Power Bi.
Yes, it is possible to add a leading zero to the numbers or month value. There are two different ways that we can add leading zero to month in Power BI. Such as,
- Using Direct Query
- Using Power Query
Approach 1 – Using Direct Query
Let us see how to add leading zero to Month using the Power Bi DAX direct query in Power Bi
- Open the Power Bi desktop and load the Products Ordered data table by using the get data option. Once the data has been loaded.
- Click on the new column under the modeling tab and use the below-mentioned formula and click on the check icon.
Direct Query = if('Products Ordered'[Month Number] < 10, "0", BLANK()) & 'Products Ordered'[Month Number]
Where,
- Direct Query = New Column Name
- Products Ordered = Table Name
- Month Number = Column Name
In the below screenshot, you can see that the new column added a leading zero to the Month number and displayed the result as expected.
This is how to add leading zero to Month using the Power Bi DAX direct query in Power Bi.
Also, check out, How to Remove Leading Zeros in Power BI
Approach 2 – Using Power Query
Let us see how to add leading zero to Month using the Power Query editor in Power Bi,
- Load the Products Ordered data table by using the get data option. Once the data has been loaded.
- Select the transform data option under the home tab as highlighted below, 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 add leading zeros to the month value and click on the OK button.
Text.End( "0" & Text.From ([Month Number] ), 2 )
- In the below screenshot, we can see that the new custom column has displayed the values with leading zero added to the month.
- Click on the Close and Apply option, so that the changes will be reflected on the Power Bi desktop.
= Table.AddColumn(#"Removed Columns", "Power Query", each Text.End( "0" & Text.From ([Month Number] ), 2 ))
- The screenshot below displays the output after adding the leading zero to the month in the Power Bi data view.
This is how to add leading zero to Month using the Power query editor in Power Bi.
These are the two different ways that we can add leading zero to Month in Power Bi.
In the Power BI tutorial, We discussed what is Power BI Add Leading Zero to Month and how to work with Power BI Add Leading Zero to Month. Also, We have learned what are the various ways to add leading zero to a month in Power BI.
You may like the following Power BI tutorials:
- Power BI Distinct Count with filter
- Power BI Convert Number to Text
- Power BI sort table by Date
- How to sort by multiple columns in Power BI
- Power BI Zip Code Starting With 0
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