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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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

View solution in original post

v-eqin-msft
Community Support
Community Support

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
v-eqin-msft
Community Support
Community Support

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

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
)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.