Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
jellis1971
Helper IV
Helper IV

"Month Number" Formula

Hi:

In Power Query Editor, I have a column showing the names of months.  

How do I create a separate column showing the number for each month (i.e., "1" for "January", "2" for February, etc.)?

Thanks!

John

1 ACCEPTED SOLUTION

Hi @jellis1971 ,

 

That's a pity... since there is no M Power Query function to reverse MonthNames to Numbers... There is always the possibility for twelve if clauses I suppose, but here another one that you might consider sufficient:

tomfox_0-1650832598258.png

 

Create a new custom column with the following code:

tomfox_1-1650832660547.png

 

Date.Month ( Date.FromText ( "1 " & [MonthName] & " 2022" ) )

 

Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8krMK00sqlSK1YlWcktNKoJzfBOLkjPALMeCoswcqBhEzqs0LxXKyIGIOJamlxaXgJnBqQUlqblJqUVgnn9yST6M7ZdfhpBwSU2GcmIB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [MonthName = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"MonthName", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "MonthNumber", each Date.Month ( Date.FromText ( "1 " & [MonthName] & " 2022" ) ))
in
    #"Added Custom"

 

Does this work for you? 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

5 REPLIES 5
Jay2022
Helper IV
Helper IV

How would i amend this to continue on for additional years (eg count to 13 14 and so on for jan, feb the following year)

v-henryk-mstf
Community Support
Community Support

Hi @jellis1971 ,

 

Whether the advice given by @tackytechtom  has solved your confusion, if the problem has been solved you can mark the reply for the standard answer to help the other members find it more quickly. If not, please point it out.


Looking forward to your feedback.


Best Regards,
Henry

jellis1971
Helper IV
Helper IV

Unfortunately, I do not.

Hi @jellis1971 ,

 

That's a pity... since there is no M Power Query function to reverse MonthNames to Numbers... There is always the possibility for twelve if clauses I suppose, but here another one that you might consider sufficient:

tomfox_0-1650832598258.png

 

Create a new custom column with the following code:

tomfox_1-1650832660547.png

 

Date.Month ( Date.FromText ( "1 " & [MonthName] & " 2022" ) )

 

Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8krMK00sqlSK1YlWcktNKoJzfBOLkjPALMeCoswcqBhEzqs0LxXKyIGIOJamlxaXgJnBqQUlqblJqUVgnn9yST6M7ZdfhpBwSU2GcmIB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [MonthName = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"MonthName", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "MonthNumber", each Date.Month ( Date.FromText ( "1 " & [MonthName] & " 2022" ) ))
in
    #"Added Custom"

 

Does this work for you? 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

tackytechtom
Super User
Super User

Hi @jellis1971 ,

 

Does your table also contain a date column corresponding the month names? If so, you can use the Date.Month function on that column.

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.