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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
bcbuckley13
Helper III
Helper III

How to convert excel formula to M (or Dax)?

Does anyone know how I would write this in M (or dax)?

 

IF(AND([Course Complete Date] <>"",[Course Complete Date]>[Due Date],"No",
IF(AND([Course Complete Date]<>"",[Course Complete Date]<[Due Date],"Yes",
IF(AND(ISBLANK([Course Complete Date],[Due Date]<TODAY()),"Overdue","Pending")))

 

bcbuckley13_0-1593613794160.png

 

 

 

1 ACCEPTED SOLUTION

Ok, try this, but this still isn't right.

                if [Course Complete Date] <> null then
                    if [Course Complete Date] > [Reg Date] then "No"
                    else if [Course Complete Date] < [Reg Date] then "Yes" else null
                else if [Course Complete Date] = null then
                    if [Reg Date] < DateTime.Date(DateTime.LocalNow()) then "Overdue" else null
                else "Pending"

The problem is you have some dates where the reg date and completed date are the same. Are you wanting all of those to be pending? If so, change to :

                if [Course Complete Date] <> null then
                    if [Course Complete Date] > [Reg Date] then "No"
                    else if [Course Complete Date] < [Reg Date] then "Yes" else "Pending"
                else if [Course Complete Date] = null then
                    if [Reg Date] < DateTime.Date(DateTime.LocalNow()) then "Overdue" else "Pending"
                else "Pending"

 The issue with the error seems to be you cannot test for null and another condition with an and operator, so I needed to split the logic into even more nested if statements.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

13 REPLIES 13
edhans
Super User
Super User

Try this:

if [Course Complete Date] <>"" and [Course Complete Date]>[Due Date] then "No"
else if [Course Complete Date]<>"" and [Course Complete Date]<[Due Date] then "Yes"
else if [Course Complete Date] = null and [Due Date]<DateTime.LocalNow() then "Overdue"
else "Pending"


Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

@edhans  Now I'm back to getting an error.

bcbuckley13_0-1593623681371.png

 

CLick on the white space next to the word "error" and tell us what the error is. It will show up in yellow at the bottom.

If you could provide sample data that would really help as we are all just guessing. Screenshots are fine for expected results, but pretty useless for actually examining and testing data.

 

How to get good help fast. Help us help you.
How to Get Your Question Answered Quickly
How to provide sample data in the Power BI Forum



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Ok, try this, but this still isn't right.

                if [Course Complete Date] <> null then
                    if [Course Complete Date] > [Reg Date] then "No"
                    else if [Course Complete Date] < [Reg Date] then "Yes" else null
                else if [Course Complete Date] = null then
                    if [Reg Date] < DateTime.Date(DateTime.LocalNow()) then "Overdue" else null
                else "Pending"

The problem is you have some dates where the reg date and completed date are the same. Are you wanting all of those to be pending? If so, change to :

                if [Course Complete Date] <> null then
                    if [Course Complete Date] > [Reg Date] then "No"
                    else if [Course Complete Date] < [Reg Date] then "Yes" else "Pending"
                else if [Course Complete Date] = null then
                    if [Reg Date] < DateTime.Date(DateTime.LocalNow()) then "Overdue" else "Pending"
                else "Pending"

 The issue with the error seems to be you cannot test for null and another condition with an and operator, so I needed to split the logic into even more nested if statements.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Thank you to everyone that help solve this!!! Such an amazing community!

@edhans @aj1973 @Greg_Deckler @BA_Pete 

glad to have assisted with your project @bcbuckley13 !



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Greg_Deckler
Community Champion
Community Champion

That code should work in DAX with minimal changes although I would recommend using SWITCH(TRUE()...) instead of nested IF statements.

 

M code is going to be something like:

 

if [Course Complete Date] <>"" and [Course Complete Date]>[Due Date] then "No" else if [Course Complete Date]<>"" and [Course Complete Date]<[Due Date] then "Yes" else if [Course Complete Date] <>"" and [Due Date] < DateTime.LocalNow() then "Overdue" else "Pending"

 

 



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

@Greg_Deckler  Thank you. However, I got the dredded Null error from the blank Course Completed date column.

 

bcbuckley13_0-1593614715866.png

 

Hi @bcbuckley13 ,

 

Use Greg's code, but instead of using <>"" use <> null

 

Pete



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

Proud to be a Datanaut!




@BA_PeteThank you. That fixed the error, but for that cell that says Pending, that one should be Overdue.

bcbuckley13_0-1593620090782.png

 

@bcbuckley13 

Replace "Pending" by "Overdue" and vice versa.

Yes No 1.PNG

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

@aj1973  That only swapped them, but didn't fix the actuall issue.

 

T30 Issue in PBI.jpg

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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