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.
How do you simply add a month number to each month?
For example: August = 08, October = 10, December = 12, etc.
Solved! Go to Solution.
@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
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
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.
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
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!
This unfortunately also doesn't work. it gives me this message:
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.
@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 , 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
)
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
113 | |
97 | |
84 | |
67 | |
60 |
User | Count |
---|---|
150 | |
120 | |
99 | |
87 | |
68 |