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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
TBSST
Frequent Visitor

DateDiff with the next availible row date

Hi All, 

 

i am trying to run a report where i am looking at the date differences between two upload dates, based on ID's.

 

IDSurvey IDSurvey DateNext Survey Required (months)
a11/01/20232
a21/03/20232
a31/05/20233
a41/07/20233
b51/01/20232
b61/04/20233
b71/07/20232
b81/10/20234
c9Jan-234
c101/05/20231
c111/07/20232
c121/09/20233

 

i am wanting to determing how many months there was between each response per client and create a new column in the table to show the months differences. The measure would be called "Days between last Survey" For example, Client a, between survey 1 and 2, it would be 2 Months, Survey 2 and 3 would be 2 months and so on. Then Client be would be survey 5 and 6 would be 3 Months and so on. The most recent surevey dates will be from the survey date to todays date. 

 

From there, i would like to create a measure that identifies how many of the surveys are out of date. So if the new measure "dats between last Survey" is greater than 'next surevey required', it will be marked as 'Late'. 

 

Any help with this would be greatly appreciated. 

 

Thank you. 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @TBSST ,

Please try to create a measure with below dax formula:

Measure =
VAR cur_id =
    SELECTEDVALUE ( 'Table'[ID] )
VAR cur_sid =
    SELECTEDVALUE ( 'Table'[Survey ID] )
VAR cur_date =
    SELECTEDVALUE ( 'Table'[Survey Date] )
VAR required_month =
    SELECTEDVALUE ( 'Table'[Next Survey Required (months)] )
VAR next_date =
    CALCULATE (
        MAX ( 'Table'[Survey Date] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[ID] = cur_id
                && 'Table'[Survey ID] = cur_sid + 1
        )
    )
VAR month_diff =
    DATEDIFF ( cur_date, next_date, MONTH )
VAR _result =
    IF (
        ISBLANK ( month_diff ),
        IF (
            DATEDIFF ( cur_date, TODAY (), MONTH ) > required_month,
            "Late",
            "Not Late"
        ),
        IF ( month_diff > required_month, "Late", "Not Late" )
    )
RETURN
    _result

vbinbinyumsft_0-1697426427031.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @TBSST ,

Please try to create a measure with below dax formula:

Measure =
VAR cur_id =
    SELECTEDVALUE ( 'Table'[ID] )
VAR cur_sid =
    SELECTEDVALUE ( 'Table'[Survey ID] )
VAR cur_date =
    SELECTEDVALUE ( 'Table'[Survey Date] )
VAR required_month =
    SELECTEDVALUE ( 'Table'[Next Survey Required (months)] )
VAR next_date =
    CALCULATE (
        MAX ( 'Table'[Survey Date] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[ID] = cur_id
                && 'Table'[Survey ID] = cur_sid + 1
        )
    )
VAR month_diff =
    DATEDIFF ( cur_date, next_date, MONTH )
VAR _result =
    IF (
        ISBLANK ( month_diff ),
        IF (
            DATEDIFF ( cur_date, TODAY (), MONTH ) > required_month,
            "Late",
            "Not Late"
        ),
        IF ( month_diff > required_month, "Late", "Not Late" )
    )
RETURN
    _result

vbinbinyumsft_0-1697426427031.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you so much! This works perfectly! 

If i could continue with your support, could you also help me write the DAX to put this into a card, so it shows me the count of 'late'. 

i am also wanting a pie graph with all survey ID's, and the legend to be late/not late. 

 

If this something you are able to help with aswell?

lbendlin
Super User
Super User

Please show the expected outcome based on the sample data you provided.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.