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
Anonymous
Not applicable

Dax statement to identify instances where comparing two different dates in different columns

Hi

Im trying to write a code that can identify where the End Date is within 2 days of the next No's Start Date and to flag that for example

NoStart DateEnd Date 
10023/03/202124/03/2021 
20025/03/202130/03/2021 
10026/03/202128/03/2021 
3001/04/20213/04/2021 
30010/04/202111/04/2021 
    
NoStart DateEnd DateWithin 2 days for same No.
10023/03/202124/03/2021Yes
20025/03/202130/03/2021No
10026/03/202128/03/2021Yes
3001/04/20213/04/2021No
30010/04/202111/04/2021No

 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

Please try the following formula:

 

Measure =
VAR lastenddate =
    MAXX (
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[No] = MAX ( 'Table'[No] )
                && 'Table'[End Date] < MAX ( 'Table'[End Date] )
        ),
        'Table'[End Date]
    )
VAR nextstartdate =
    MINX (
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[No] = MAX ( 'Table'[No] )
                && 'Table'[Start Date] > MAX ( 'Table'[Start Date] )
        ),
        'Table'[Start Date]
    )
VAR E_N_S = DATEDIFF ( MAX ( 'Table'[End Date] ), nextstartdate, DAY )
VAR S_L_E = DATEDIFF ( lastenddate, MAX ( 'Table'[Start Date] ), DAY )
RETURN
    IF ( E_N_S <= 2 && S_L_E <= 2 && E_N_S + S_L_E <> BLANK (), "Yes", "No" )

vkkfmsft_0-1646099514759.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
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

4 REPLIES 4
VahidDM
Super User
Super User

@Anonymous 

 

BTW, you can find the days between End and next Start date with this code:

Within 2 days for same No. = 
Var _END = 'Table'[End Date]
Var _NextStart = CALCULATE(min('Table'[Start Date]),filter(all('Table'),'Table'[Start Date]>EARLIER('Table'[Start Date])&&'Table'[No]=EARLIER('Table'[No])))
Var _Diff = DATEDIFF(_END,_NextStart,DAY)
return
_Diff

 

output:

VahidDM_0-1645767389041.png

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

VahidDM
Super User
Super User

HI @Anonymous 

 

How did you calculate YES for second line of 100 with 28-Mar-21 end and no other line in the table?

 

 


Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

Anonymous
Not applicable

So the yes is because of line 1 and line 3 is taking leave within two days, by comparing the end date of each number (ID 100) and comparing it to the next occurance for that number (ID100) if the start date is within 2 days. Hope that makes sense.

Hi @Anonymous ,

 

Please try the following formula:

 

Measure =
VAR lastenddate =
    MAXX (
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[No] = MAX ( 'Table'[No] )
                && 'Table'[End Date] < MAX ( 'Table'[End Date] )
        ),
        'Table'[End Date]
    )
VAR nextstartdate =
    MINX (
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[No] = MAX ( 'Table'[No] )
                && 'Table'[Start Date] > MAX ( 'Table'[Start Date] )
        ),
        'Table'[Start Date]
    )
VAR E_N_S = DATEDIFF ( MAX ( 'Table'[End Date] ), nextstartdate, DAY )
VAR S_L_E = DATEDIFF ( lastenddate, MAX ( 'Table'[Start Date] ), DAY )
RETURN
    IF ( E_N_S <= 2 && S_L_E <= 2 && E_N_S + S_L_E <> BLANK (), "Yes", "No" )

vkkfmsft_0-1646099514759.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

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.