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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Niels_T
Post Patron
Post Patron

How to assign month number to each month

How do you simply add a month number to each month?

 

For example: August = 08, October = 10, December = 12, etc.

 

Niels_T_0-1609424758210.png

 

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@Niels_T , Create a new column like

 

Switch( True() ,
[month of year] = "August" , "08",
[month of year] = "October" , "10",
[month of year] = "December " , "12",
//add others
)

 

refer: https://www.youtube.com/watch?v=gelJWktlR80

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

Anonymous
Not applicable

Hi @Niels_T ,

 

According to my understanding, you want to convert month name to number simply.Please follow these steps in Power Query as shown below:
Add custom column-->Change data type-->remain only Date.Month

1.4.2.1.gif

Here is the whole M syntax:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcixNLy0uUYrViVbyTy7JT0otArNdUpNTc2Ecv/wyBCc4taAEwfMqzamEMvJSwQzfxEooXZScAWY5FhRl5kAUJeaVJhZB5N1Sk4ognFgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Month of Year" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Month Number", each [Month of Year]&" 1"),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"Month Number", type date}}),
    #"Extracted Month" = Table.TransformColumns(#"Changed Type",{{"Month Number", Date.Month, Int64.Type}})
in
    #"Extracted Month"

Please take a look at the pbix file here.

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Hi @Niels_T ,

 

According to my understanding, you want to convert month name to number simply.Please follow these steps in Power Query as shown below:
Add custom column-->Change data type-->remain only Date.Month

1.4.2.1.gif

Here is the whole M syntax:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcixNLy0uUYrViVbyTy7JT0otArNdUpNTc2Ecv/wyBCc4taAEwfMqzamEMvJSwQzfxEooXZScAWY5FhRl5kAUJeaVJhZB5N1Sk4ognFgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Month of Year" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Month Number", each [Month of Year]&" 1"),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"Month Number", type date}}),
    #"Extracted Month" = Table.TransformColumns(#"Changed Type",{{"Month Number", Date.Month, Int64.Type}})
in
    #"Extracted Month"

Please take a look at the pbix file here.

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

A good simple solution, works for me, thanks!

littlemojopuppy
Community Champion
Community Champion

Create a new column and use the MONTH() function

This unfortunately also doesn't work. it gives me this message:

 

Niels_T_0-1609426813905.png

 

I think that it has to do with my months of year's data type not being a date but instead text. I then tried to change the months of year into a date but this gives an error as well.

amitchandak
Super User
Super User

@Niels_T , Create a new column like

 

Switch( True() ,
[month of year] = "August" , "08",
[month of year] = "October" , "10",
[month of year] = "December " , "12",
//add others
)

 

refer: https://www.youtube.com/watch?v=gelJWktlR80

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hello,

 

I get this message:

 

Niels_T_0-1609426329866.png

 

@Niels_T , remove comma at last. I kept it so that you can add more argument 

 

Switch( True() ,
[month of year] = "August" , "08",
[month of year] = "October" , "10",
[month of year] = "December " , "12",
1
)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.

Top Solution Authors