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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
fabiolamelo
Helper II
Helper II

Compare 2 Dates - IF Condition - HELP

Hi everyone,

 

I`m working on one project that I need to compare two columns date, which are:

 

Contract Date | Renewed Contract  Date 

27/01/2021    |        26/01/2021                  

27/01/2021    |        28/01/2021                  

 

If "Renewed Contract Date " is bigger than "Contract Date" inform "Late" if not "Anticipated".For example"

Contract Date | Renewed Contract  Date | 

27/01/2021    |        26/01/2021               | "Anticipated"

27/01/2021    |        28/01/2021               | "Late"

 

My idea is using the IF condition but I didn't find an away to compare two dates using this condition, can you please 

Can you please help me with it?

Thanks

1 ACCEPTED SOLUTION
edhans
Super User
Super User

If you want a calculated column @fabiolamelo then the solution by @danextian is what you need. If you want to do this in Power Query, you would use this:

= if [Date1] > [Date2] then "Late" else "Anticipated"

If you need this in a measure, you will need to provide a bit more details with some data so we can help, but one fast way to try this is to use this measure:

Status =
IF(
    MAX( 'Table'[Date1] )
        > MAX( 'Table'[Date2] ),
    "Late",
    "Anticipated"
)

But that is a total stab in the dark as I don't know your expected output - not late/anticipated - but how you want to express it in a visual.

How to get good help fast. Help us help you.

How To Ask A Technical Question If you Really Want An Answer

How to Get Your Question Answered Quickly - Give us a good and concise explanation
How to provide sample data in the Power BI Forum - Provide data in a table format per the link, or share an Excel/CSV file via OneDrive, Dropbox, etc.. Provide expected output using a screenshot of Excel or other image. Do not provide a screenshot of the source data. I cannot paste an image into Power BI tables.



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

3 REPLIES 3
edhans
Super User
Super User

If you want a calculated column @fabiolamelo then the solution by @danextian is what you need. If you want to do this in Power Query, you would use this:

= if [Date1] > [Date2] then "Late" else "Anticipated"

If you need this in a measure, you will need to provide a bit more details with some data so we can help, but one fast way to try this is to use this measure:

Status =
IF(
    MAX( 'Table'[Date1] )
        > MAX( 'Table'[Date2] ),
    "Late",
    "Anticipated"
)

But that is a total stab in the dark as I don't know your expected output - not late/anticipated - but how you want to express it in a visual.

How to get good help fast. Help us help you.

How To Ask A Technical Question If you Really Want An Answer

How to Get Your Question Answered Quickly - Give us a good and concise explanation
How to provide sample data in the Power BI Forum - Provide data in a table format per the link, or share an Excel/CSV file via OneDrive, Dropbox, etc.. Provide expected output using a screenshot of Excel or other image. Do not provide a screenshot of the source data. I cannot paste an image into Power BI tables.



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 

I didn't know that using MAX the IF condition for this case will works 🙂 Thank you so much for your help, I`m using the measure with MAX as you suggest and it was perfect 🙂 God bless you!

danextian
Super User
Super User

Try something like this:
IF ( 'Table'[Renewed Contract Date] > 'Table'[Contract Date],  "Late",  "Anticipated"  ).










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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