Power BI Add Leading Zero to Month

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.
add Leading Zero to Month in the Power BI
add Leading Zero to Month in the Power BI

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 1Using 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,

  1. Direct Query = New Column Name
  2. Products Ordered = Table Name
  3. Month Number = Column Name
See also  Power BI Group by Column [With Various Examples]

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.

Power BI add Leading Zero to Month
Power BI add Leading Zero to Month

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 2Using 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.
Power query convert number to text example
Power BI add leading zero to month
  • In the Power query editor, select the Add Column-> Add a Custom column as shown below:
Example to convert number to text with leading zeros in Power BI
Power BI add leading zero to month
  • 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 )
Example of Power BI add Leading Zero to Month
Example of Power BI add Leading Zero to Month
  • 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 ))
add Leading Zero to Month in Power BI
add Leading Zero to Month in Power BI
  • The screenshot below displays the output after adding the leading zero to the month in the Power Bi data view.
add Leading Zero to Month in Power BI example
add Leading Zero to Month in Power BI example

This is how to add leading zero to Month using the Power query editor in Power Bi.

See also  Card Visual 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:

>