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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
maurcoll
Helper III
Helper III

Datediff at row level using a max date

Hi

I need some help please with a measure to calculate the difference between 2 dates where i need to show how long before the next review is due at row level. I have a list of customers and the dates they have been contacted. At a minimum they should be contacted within 6 months.
The issue is have is that customers can be contacted multiple times and how i currently have the table set up it is bringing the difference between the dates based on the row contact date i need it to show against the last contact date on all rows for the same customer.
I have created a calculated column that is a Yes, No for the latest contact date against each customer.
Days to next contact is based on the difference between today and the 6 month maximum time between contacts. In the example below the days to next contact for Customer A I would like to show as 144 in both rows. 

CustomerDate of ContactDays to next contact
A20/12/2024141
A23/12/2024144
B27/12/2024148
C29/01/2025180


This is the current measure

VAR LastContactDate = MAX('Customer '[Date of Contact])
VAR NextContacttDate = EDATE(LastContactDate, 6)
VAR Today = TODAY()
VAR DaysRemaining = DATEDIFF(Today, NextContactDate, DAY)

RETURN

    IF(
        DaysRemaining >= 0,
        DaysRemaining & " days left",
        BLANK()
    )
1 ACCEPTED SOLUTION
Uzi2019
Super User
Super User

Hi @maurcoll 

 

Try this measure

Measure Final =
VAR LastContactDate = CALCULATE(MAX(Issue[Date of Contact]),ALLEXCEPT(Issue,Issue[Customer]))

VAR NextContactDate = EDATE(LastContactDate, 6)
VAR Today = TODAY()
VAR DaysRemaining = DATEDIFF(Today, NextContactDate, DAY)

RETURN

   IF(
        DaysRemaining >= 0,
        DaysRemaining & " days left",
        BLANK()
    )
 
Uzi2019_0-1738230687613.png

 

 

I hope I answered your question!

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

View solution in original post

4 REPLIES 4
Uzi2019
Super User
Super User

Hi @maurcoll 

 

Try this measure

Measure Final =
VAR LastContactDate = CALCULATE(MAX(Issue[Date of Contact]),ALLEXCEPT(Issue,Issue[Customer]))

VAR NextContactDate = EDATE(LastContactDate, 6)
VAR Today = TODAY()
VAR DaysRemaining = DATEDIFF(Today, NextContactDate, DAY)

RETURN

   IF(
        DaysRemaining >= 0,
        DaysRemaining & " days left",
        BLANK()
    )
 
Uzi2019_0-1738230687613.png

 

 

I hope I answered your question!

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

HI @maurcoll 

 

I have tested your measure all working fine Max date needs t be fixed with ALLEXCEPT function.  I have already given you the formula in above post. Try that..

 

I hope I answered your question!

 

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

That has worked, thank you

 

danextian
Super User
Super User

Hi @maurcoll 

 

I don't know what result you expect but if you want to compare against the latest contact date per customer, try this:

 

Test =
VAR LastContactDate =
    CALCULATE (
        MAX ( 'Table'[Date of Contact] ),
        ALLEXCEPT ( 'Table', 'Table'[Customer] )
    )
VAR NextContactDate =
    EDATE ( LastContactDate, 6 )
VAR Today =
    TODAY ()
VAR DaysRemaining =
    DATEDIFF ( Today, NextContactDate, DAY )
RETURN
    IF ( DaysRemaining >= 0, DaysRemaining & " days left", BLANK () )

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"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
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.

Top Kudoed Authors