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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
samc_26
Helper IV
Helper IV

Days between multiple dates

Hi all,

 

I have a table that is set up like the below (changed data for this!) and I'm trying to find out the number of days between each date so that I can calculate an average. This is how my data is laid out at present.

 

ProductOrder DateColumn I would like to create ( days in-between dates listed by product)
Notebook01/01/250
Notebook18/02/2548
Notebook28/02/259
Pencil28/02/250
Pencil14/03/2514
Pencil22/04/2539
Eraser19/05/2527
Eraser21/06/2538

 

What I would like is a way of showing individual days between each order so it would show something like what is in the third column. I have no idea if this is possible, I would be extremley grateful if anyone can work it out! I've managed to write a measure using DATEDIFF which shows me the days between the earliest and latest date but it's the time in between each order I need really. 

 

Thank you for reading! 😀

2 ACCEPTED SOLUTIONS
FBergamaschi
Super User
Super User

FBergamaschi_2-1756994609091.png

 

I named the table Fact

 

Created a key calc column 

 

key = 'Fact'[Order Date] & 'Fact'[Product]

 

DAX code of the calc column Delta Days

 

Delta Days =
VAR keyRow = 'Fact'[key]
VAR Prevkey = MAXX ( FILTER ( VALUES( 'Fact'[key] ), 'Fact'[key] < keyRow ), 'Fact'[key] )
VAR PrevDate = CALCULATE( SELECTEDVALUE( 'Fact'[Order Date] ), 'Fact'[key] = Prevkey, REMOVEFILTERS() )
RETURN
IF (
    NOT ISBLANK( Prevkey ),
    INT('Fact'[Order Date] - PrevDate)
)
 

If this helped, please consider giving kudos and mark as a solution

@mein replies or I'll lose your thread

Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page

Consider voting this Power BI idea

Francesco Bergamaschi

MBA, M.Eng, M.Econ, Professor of BI

View solution in original post

Shahid12523
Community Champion
Community Champion

Days Between =
VAR CurrentDate = 'Table'[Order Date]
VAR PrevDate =
CALCULATE (
MAX ( 'Table'[Order Date] ),
FILTER (
'Table',
'Table'[Product] = EARLIER ( 'Table'[Product] )
&& 'Table'[Order Date] < EARLIER ( 'Table'[Order Date] )
)
)
RETURN
IF ( ISBLANK ( PrevDate ), 0, DATEDIFF ( PrevDate, CurrentDate, DAY ) )

Shahed Shaikh

View solution in original post

4 REPLIES 4
Shahid12523
Community Champion
Community Champion

Days Between =
VAR CurrentDate = 'Table'[Order Date]
VAR PrevDate =
CALCULATE (
MAX ( 'Table'[Order Date] ),
FILTER (
'Table',
'Table'[Product] = EARLIER ( 'Table'[Product] )
&& 'Table'[Order Date] < EARLIER ( 'Table'[Order Date] )
)
)
RETURN
IF ( ISBLANK ( PrevDate ), 0, DATEDIFF ( PrevDate, CurrentDate, DAY ) )

Shahed Shaikh

Thank you so much, this worked perfectly!! Much appreciated 💪

FBergamaschi
Super User
Super User

FBergamaschi_2-1756994609091.png

 

I named the table Fact

 

Created a key calc column 

 

key = 'Fact'[Order Date] & 'Fact'[Product]

 

DAX code of the calc column Delta Days

 

Delta Days =
VAR keyRow = 'Fact'[key]
VAR Prevkey = MAXX ( FILTER ( VALUES( 'Fact'[key] ), 'Fact'[key] < keyRow ), 'Fact'[key] )
VAR PrevDate = CALCULATE( SELECTEDVALUE( 'Fact'[Order Date] ), 'Fact'[key] = Prevkey, REMOVEFILTERS() )
RETURN
IF (
    NOT ISBLANK( Prevkey ),
    INT('Fact'[Order Date] - PrevDate)
)
 

If this helped, please consider giving kudos and mark as a solution

@mein replies or I'll lose your thread

Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page

Consider voting this Power BI idea

Francesco Bergamaschi

MBA, M.Eng, M.Econ, Professor of BI

johnt75
Super User
Super User

You could create a calculated column like

Days since previous order = 
VAR CurrentDate = 'Table'[Order Date]
VAR PrevDate = SELECTCOLUMNS(
    OFFSET( 1, 
        ALL( 'Table'[Product], 'Table'[Order Date] ), 
        ORDERBY( 'Table'[Order Date], DESC ),
        PARTITIONBY( 'Table'[Product] )
    ), 
    'Table'[Order Date]
)
VAR Result = DATEDIFF( PrevDate, CurrentDate, DAY )
RETURN Result

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.