Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I followed a formula found on this forum, confirmed as the solution to changing a column of month names to date format in a new column and Power Query is rejecting the use of SWITCH. Why is this a confirmed answer if PQ doesn't recognise the function?
This is what I have, copied almost verbatum (Col names changed is all):
= Table.AddColumn(#"Changed Type4", "Month Num", each SWITCH([Month],
"January", Format (Date(2020,1,1), m),
"February", Format (Date(2020,2,1), m),
"March", Format (Date(2020,3,1), m),
"April", Format (Date(2020,4,1), m),
"May", Format (Date(2020,5,1), m),
"June", Format (Date(2020,6,1), m),
"July", Format (Date(2020,7,1), m),
"August", Format (Date(2020,8,1), m),
"September", Format (Date(2020,9,1), m),
"October", Format (Date(2020,10,1), m),
"November", Format (Date(2020,11,1), m),
"December", Format (Date(2020,12,1), m)
))
I need ot make a cumulative sum column by month (ie, Total for January, then total for Jan and Feb, so on). All I have is the month name in the source data. If anyone know what I'm doing wrong please help.
Solved! Go to Solution.
Hi @LYorkToenniges,
That solutions appears to be a calculated column (DAX) not a custom column (Power Query). To get the month number from a month name, enter this in to the formula area of the Add Custom Column dialog box:
Date.Month( Date.From( [Month] & "- 2020"))
Based on your example I assumed your month name field is called: [Month] by appending a year, the string can be converted into a date value from which a month number can be obtained.
I hope this is helpful
@LYorkToenniges @m_dekorte is absolutely correct. SWITCH is a DAX function, there is no native switch or case function in Power Query. Please reply with a link to the forum post you found so that I can unmark the post as the solution because it is clearly not correct.
This was the reference I was using:
https://community.fabric.microsoft.com/t5/Desktop/Converting-month-name-to-date/td-p/2938608
Maybe I'm misunderstanding how they are creating the calculated column. It seems the only way is in power query, am I missing a way to make columns with dax formulas? I've only used it to create measures.
Hi @LYorkToenniges,
That solutions appears to be a calculated column (DAX) not a custom column (Power Query). To get the month number from a month name, enter this in to the formula area of the Add Custom Column dialog box:
Date.Month( Date.From( [Month] & "- 2020"))
Based on your example I assumed your month name field is called: [Month] by appending a year, the string can be converted into a date value from which a month number can be obtained.
I hope this is helpful