Forum Discussion
Khomotjo
Helper II
1 year agoConvert Month Name to Month No
Hello Everyone, I have a coloumn that has month names and want to convert these to integers so that I can use Date function( I have coloumns that have the day and the year ). I tried : switch ...
- 1 year ago
Hi Khomotjo ,
Please use the bellow DAX to achieve your goal:
MonthNumber = SWITCH( TRUE(), 'Table'[month_name] = "January", 1, 'Table'[month_name] = "February", 2, 'Table'[month_name] = "March", 3, 'Table'[month_name] = "April", 4, 'Table'[month_name] = "May", 5, 'Table'[month_name] = "June", 6, 'Table'[month_name] = "July", 7, 'Table'[month_name] = "August", 8, 'Table'[month_name] = "September", 9, 'Table'[month_name] = "October", 10, 'Table'[month_name] = "November", 11, 'Table'[month_name] = "December", 12, BLANK() -- Default case if no match is found )Make sure to replace 'Table'[month_name] with name of your table and column that contain months as String
Uzi2019
Community Champion
1 year agoHi Khomotjo
Try below dax and create calculated column
MonthNo = SWITCH('Year - Month'[Month],
"Jan", 1,
"Feb",2,
"Mar",3,
"Apr",4,
"May",5,
"Jun",6,
"Jul",7,
"Aug",8,
"Sep",9,
"Oct",10,
"Nov",11,
"Dec",12
)
Or try this
or you can try this to create date column
Month Name =
SWITCH(Table[Month],
"January", Format (Date(2020,1,1), “mmm”),
"February", Format (Date(2020,2,1), “mmm”),
//and so on for the rest of the months
)
I hope above method would work for you.
I hope I answered your question!