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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
JohnNPBIUser
Regular Visitor

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
Regular Visitor

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
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

Top Solution Authors
Top Kudoed Authors