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
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 )

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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]
)

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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

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!

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.