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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
LYorkToenniges
Helper II
Helper II

Switch in Power Query?

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.

1 ACCEPTED SOLUTION
m_dekorte
Super User
Super User

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

 

View solution in original post

3 REPLIES 3
Greg_Deckler
Community Champion
Community Champion

@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.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

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.

m_dekorte
Super User
Super User

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

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.