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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Dunner2020
Post Prodigy
Post Prodigy

Converting DAX code into M

Hi there,

 

I have a column which I created using the DAX function. I wanted to create the same column in the power query editor (and want to get rid of the column created using DAX). 

Month Number = SWITCH([Month Name],
"April",1,
"May",2,
"June",3,
"July",4,
"August",5,
"September",6,
"October",7,
"November",8,
"December",9,
"January",10,
"February",11,
12
)
 
When I applied the same formula in power query editor I got the following error:

However, I got the following error:

myasir_0-1600227470953.png

Could anyone help me in converting DAX code into M language?

 

1 ACCEPTED SOLUTION
VasTg
Memorable Member
Memorable Member

@Dunner2020 

 

Try the conditional column and assign your appropriate value. The below image is just an example.

 

image.png

 

If it helps, mark it as a solution

Kudos are nice too

Connect on LinkedIn

View solution in original post

4 REPLIES 4
v-diye-msft
Community Support
Community Support

Hi @Dunner2020 

 

If the above posts help, please kindly mark it as a answer to help others find it more quickly. thanks!

If not, please kindly elaborate more.

 

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.
Anonymous
Not applicable

Hi @Dunner2020- I am not sure if i got this right but are you trying in power Query Editor to convert MonthName to Numbers. 

I added a new Column from Example and mapped the months, M Code generated itself was something on the lines: 

 

= Table.AddColumn(#"Renamed Columns", "Custom", each if [Month Name] = "Jan" then 10 else if [Month Name] = "Feb" then 11 else if [Month Name] = "Mar" then 12 else if [Month Name] = "Apr" then 1 else if [Month Name] = "May" then 2 else if [Month Name] = "June" then 3 else if [Month Name] = "July" then 4 else if [Month Name] = "Aug" then 5 else if [Month Name] = "Sep" then 6 else if [Month Name] = "Oct" then 7 else if [Month Name] = "Nov" then 8 else if [Month Name] = "Dec" then 9 else null, type number)

 

and i then removed the MonthName column

 

Does this help?

 

amitchandak
Super User
Super User

@Dunner2020 , same thing as been done and explained nicely in this article -https://www.thebiccountant.com/2018/02/15/generic-switch-function-query-editor-in-power-bi-and-power...

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
VasTg
Memorable Member
Memorable Member

@Dunner2020 

 

Try the conditional column and assign your appropriate value. The below image is just an example.

 

image.png

 

If it helps, mark it as a solution

Kudos are nice too

Connect on LinkedIn

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.