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
Arial12
Frequent Visitor

Date difference between concecutive order date and ship date for each customer

Hello Expert,

 

please am in need of your help

 

custID                   Orderdt.                  Shipdt.           daysbetweenorder(first shipdt - second (next orderdt) orderdt

123                        1/1/2014                 1/3/2014        3 

123                        1/6/2014                 1/10/2014      2

123.                       1/12/2014               1/14/2014       Null 

234                         1/1/2014                1/4/2014         28       

234.                        2/1/2014                 2/2/2014.       Null

 

 

for the first row each customer , datediff 1/3/2014 , 1/6/2014 = 3 days

same customer second row, datediff    1/10/2014,  1/12/2014 = 2 days

same customer third row ,  for now is the last shipdt so that can be null or blank until that same customer orders it again and I want this to be dynamic so that it will auto calculate the difference for every customer.

 

2 ACCEPTED SOLUTIONS

@Arial12

 

it works with sample data.... but if the days are overlapping... it might not work

 

daysdiff.png


Regards
Zubair

Please try my custom visuals

View solution in original post

Thank you Zubair_Muhammad.

For any overlapping, i created a new column which give me nextdt for each row 

NextDT=CALCULATE(MIN(Table[Orderdt]),FILTER(Table,Table[Custid]=EARLIER(Table[Custid]) && Table[Orderdt] > EARLIER(table[Orderdt])))

 

and comaparion between the dates orderdt and NextDT and getting datediff.

 

Thanks,

 

View solution in original post

3 REPLIES 3
Zubair_Muhammad
Community Champion
Community Champion

Hi @Arial12

 

Try this calculated column

 

Days between orders =
VAR CurrentRowOrderDate = TableName[Orderdt.]
VAR NextOrder =
    CALCULATE (
        MIN ( TableName[Orderdt.] ),
        FILTER (
            ALLEXCEPT ( TableName, TableName[custID] ),
            TableName[Orderdt.] > CurrentRowOrderDate
        )
    )
RETURN
    DATEDIFF ( TableName[Shipdt.], NextOrder, DAY )

Regards
Zubair

Please try my custom visuals

@Arial12

 

it works with sample data.... but if the days are overlapping... it might not work

 

daysdiff.png


Regards
Zubair

Please try my custom visuals

Thank you Zubair_Muhammad.

For any overlapping, i created a new column which give me nextdt for each row 

NextDT=CALCULATE(MIN(Table[Orderdt]),FILTER(Table,Table[Custid]=EARLIER(Table[Custid]) && Table[Orderdt] > EARLIER(table[Orderdt])))

 

and comaparion between the dates orderdt and NextDT and getting datediff.

 

Thanks,

 

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.