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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
JohnNPBIUser
Advocate I
Advocate I

Convert DAX to M Code

Hi,

I am trying to add a column via Power Query M.  How do I convert this DAX code to M language:

IF (
YEAR ( 'Dummy Data'[Admissions Month] )
= YEAR ( DATE(YEAR(TODAY()),

MONTH(TODAY())-1,DAY(TODAY())) )
&& MONTH ( 'Dummy Data'[Admissions Month] ) = MONTH ( DATE(YEAR(TODAY()),MONTH(TODAY())-1,DAY(TODAY())) ),
"Last Month",
'Dummy Data'[Admissions Month]
)

Thanks for your help.

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @JohnNPBIUser ,

 

I think you can hugely simplify this down to:

if Date.StartOfMonth([AdmissionsMonth]) = Date.StartOfMonth(Date.AddMonths(Date.From(DateTime.LocalNow()), -1))
then "Last Month"
else [AdmissionsMonth]

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

2 REPLIES 2
JohnNPBIUser
Advocate I
Advocate I

Thank you for your help, much appreciated  👍

BA_Pete
Super User
Super User

Hi @JohnNPBIUser ,

 

I think you can hugely simplify this down to:

if Date.StartOfMonth([AdmissionsMonth]) = Date.StartOfMonth(Date.AddMonths(Date.From(DateTime.LocalNow()), -1))
then "Last Month"
else [AdmissionsMonth]

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors