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
michael_knight
Post Prodigy
Post Prodigy

DateDiff of same column, but only look into the future once

Hi All,

 

I'm trying to a datediff of the same column but only looking into the future once, the data is below. I created a measure which gives me the Weeks Between, but I don't want to include the top two as I only want to look at one date in the future

 

Interview DateStatusWeeks between attended intExpected Outcome
16/03/2022Not Known16 
22/12/2021Not Known4 
08/12/2021Not Known22
26/11/2021Attended44
19/11/2021Failed to Attend33
11/11/2021Failed to Attend22
05/11/2021Failed to Attend11
28/10/2021Attended  

 

 

 

 

Weeks between attended int = 
VAR temp =
    TOPN (
        1,
        FILTER (
            Interview,
            Interview[ID] = EARLIER ( Interview[ID] )
                && Interview[Interview Date] < EARLIER ( Interview[Interview Date] ) && Interview[Status] = "Attended"
        ),
        Interview[Interview Date], DESC
    )


RETURN
 DATEDIFF ( MINX ( temp, Interview[Interview Date] ), Interview[Interview Date], week )

 

 

 

Thanks,

Mike

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

HI @michael_knight,

It seems like you want to calculate the datediff until the first future date, right? If that is the case, you can add a variable to get the first future date and if statement to compare the current date with that to prevent calculation on the following date ranges.

Weeks diff =
VAR _firstfuture =
    MINX ( FILTER ( Interview, [Interview Date] > TODAY () ), [Interview Date] )
VAR _nextDate =
    MINX (
        FILTER ( Interview, [Interview Date] > EARLIER ( Interview[Interview Date] ) ),
        [Interview Date]
    )
RETURN
    IF (
        Interview[Interview Date] <= _firstfuture,
        DATEDIFF ( Interview[Interview Date], _nextDate, WEEK )
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

5 REPLIES 5
v-shex-msft
Community Support
Community Support

HI @michael_knight,

It seems like you want to calculate the datediff until the first future date, right? If that is the case, you can add a variable to get the first future date and if statement to compare the current date with that to prevent calculation on the following date ranges.

Weeks diff =
VAR _firstfuture =
    MINX ( FILTER ( Interview, [Interview Date] > TODAY () ), [Interview Date] )
VAR _nextDate =
    MINX (
        FILTER ( Interview, [Interview Date] > EARLIER ( Interview[Interview Date] ) ),
        [Interview Date]
    )
RETURN
    IF (
        Interview[Interview Date] <= _firstfuture,
        DATEDIFF ( Interview[Interview Date], _nextDate, WEEK )
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
amitchandak
Super User
Super User

@michael_knight , a new column

 

Weeks between attended int =
VAR temp =
MAXX (
FILTER (
Interview,
Interview[ID] = EARLIER ( Interview[ID] )
&& Interview[Interview Date] < EARLIER ( Interview[Interview Date] ) && Interview[Status] = "Attended"
),
Interview[Interview Date], DESC
)


RETURN
DATEDIFF ( MIN ( temp, Interview[Interview Date] ), Interview[Interview Date], week )

 

 

a new measure

 

Weeks between attended int =
VAR temp =
MAXX (
FILTER (
allselected(Interview),
Interview[ID] = MAx( Interview[ID] )
&& Interview[Interview Date] < MAx( Interview[Interview Date] ) && Interview[Status] = "Attended"
),
Interview[Interview Date], DESC
)


RETURN
DATEDIFF ( temp , min(Interview[Interview Date]), week )

Hi @amitchandak 

 

Thanks for the reply, I tried the column one you sent and it didn't work. There is a red line under 

'Interview[Interview Date], DESC'
 
Thanks

@michael_knight , sorry my bad try

 

a new column

 

Weeks between attended int =
VAR temp =
MAXX (
FILTER (
Interview,
Interview[ID] = EARLIER ( Interview[ID] )
&& Interview[Interview Date] < EARLIER ( Interview[Interview Date] ) && Interview[Status] = "Attended"
),
Interview[Interview Date]
)


RETURN
DATEDIFF ( MIN ( temp, Interview[Interview Date] ), Interview[Interview Date], week )

 

 

a new measure

 

Weeks between attended int =
VAR temp =
MAXX (
FILTER (
allselected(Interview),
Interview[ID] = MAx( Interview[ID] )
&& Interview[Interview Date] < MAx( Interview[Interview Date] ) && Interview[Status] = "Attended"
),
Interview[Interview Date]
)

Thanks, tried it out and it gives the same result of the measure that I've got unfortunatly 

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.