In this Power BI tutorial, we will learn how to convert month numbers to month names in Power BI.
We will also see how to get the month name from the date and how to convert the month number to the month name in the Power Query editor.
Convert Month Number to Month Name in Power BI
Let’s say you’re analyzing sales data in Power BI. You have a dataset with a column that contains the month number (1 for January, 2 for February, and so on), but you want to display the month names (January, February, etc.) in your reports instead.
Here, I have a SharePoint list (Monthly Sales Data) that contains below columns:
Now follow the below steps:
1. Load the SharePoint link above into your Power BI Desktop, and then you can see the data in the data pane.
2. Here, I created two visuals. One is a slicer visual that displays only the month numbers, and the other is a column chart that shows sales organized by month numbers.
3. Go to the Table view, then under the Table tools, click the New column.
4. In the formula bar, enter the following formula, then click the commit button.
MonthName = FORMAT(DATE(1, [Month Number], 1), "MMMM")
Where:
- MonthName = Name of the measure where the month name is stored.
- FORMAT() = This function is used to format a given value according to a specified format.
- DATE(1, [Month Number], 1) = This function creates a date using the year 1, the provided month number, and day 1.
- “MMMM” = This is a format string used with the FORMAT function to display the full name of the month from a given date.
5. Then, you can see a new column added in the Table view.
6. In the report view, change the slicer from displaying month numbers to displaying month names. Also, adjust the column chart to show sales by month names.
This way, you can convert the month number to the month name in Power BI.
Power BI Get Month Name From Date
Now, in the above SharePoint list, I add one more column, i.e., the date column.
Now we see how to get the month name from the date. Follow the below steps:
Here, I load the data again, this time removing the month number column and adding the date column.
Under the Modeling tab, click New column.
In the formula bar, put the formula below. Then click the Commit button.
Month Name = FORMAT('Monthly Sales Data (2)'[Date],"MMMM")
Next, navigate to the table view, where you’ll notice that the month name column has been generated from the date column.
This way, you can extract the month name from the date in Power BI.
Power Query Month Number to Name
Now, we see how to convert the month number to the month name in the Power Query editor.
Here, I have two columns in Power Query. One column is the month number and sales.
Then, in the Power Query Editor, click Custom Column under Add Column.
After that, the Custom Column window will open. Here, name the new column ‘Month Name’ and paste the formula into the Custom column formula box. Then, click OK.
Date.MonthName(#date(2024, [Month Number], 1))
Where:
- #date(2024, [Month Number], 1) = This part creates a date using the year 2024, the month number from your dataset (represented by [Month Number]), and the day 1. So, if your dataset has a month number of 1, it will create the date January 1, 2040.
- Date.MonthName() = This function takes a date as input and returns the name of the month associated with that date. So, if the date is January 1, 2024, it will return to “January.”
Then, you can see a new column added in the Power Query Editor.
You can get the month name from the month number in Power Query.
I hope this tutorial provided you with all the necessary information. In this tutorial, we learned how to convert month numbers to month names in Power BI, how to extract the month name from a date, and how to perform the conversion from month number to month name in the Power Query editor.
You may also like the following tutorials:
- How to Filter Between Two Dates in Power B
- Power BI Sum Multiple Columns
- Power BI Divide Two Columns
- Create Power BI Bookmarks
- Stacked Column Chart 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