Convert month Name to Month Number in Power BI

Tip of the day

You probably found yourself handling data which have a month names instead of month numbers while setting up a PowerBI solution. Here is a simple tip on how you can convert a month name to a month number in Power BI.

Assuming you have a dataset with month names instead of month numbers, this is what you do:

Code for Convert to Month _Number

Click Data View in left side panel of Power BI. This should show your dataset. Choose the dataset you are working on.

Create a new column in this dataset(eg: Column_name:Month_Number)

Click on the Measure Box to display the query editor. Type in the following line to convert

Month_Number = SWITCH([MONTH],”August”,08,”December”,12,”July”,07,”November”,11,”October”,10,”September”,09,”April”,04,”February”,02,”January”,01,”March”,03,”May”,05,”June”,06)
* Replace the word "MONTH" in above line of code with the name of the field containing the month name.


Your new column will contain the month numbers. You can now use the “Month_Number” column as required.

Tagged with: