Forum Discussion

PolarBear's avatar
PolarBear
Icon for Helper I rankHelper I
6 years ago
Solved

Calculate Avg. Days in Status by Priority

I've been trying to figure out a way to do this for several days, but can't get it worked out.  Hoping someone one here can help me.

I have a status table that gets updated by employees whenever the status of an order changes and a Priority table that is set by the customer (note: the customer can change the priority at any time), examples of the tables:

IDDatePriority
10821/15/20201
20451/18/20203
20611/19/20204
10821/20/20203
20451/21/20205

 

IDDateStatus
10821/15/2020Ordered
20451/18/2020Ordered
20611/19/2020Ordered
10821/18/2020Ready for Shipment
20451/20/2020Ready for Shipment
20611/20/2020Ready for Shipment
10821/21/2020Shipped
20451/21/2020Shipped
20611/21/2020Shipped

 

I need to find the avg. number of days spent in each status by each priority (for all orders). DateDiff works to tell me how long in each status, but I don't know how to couple that with the dates in priority. Also, I thought about creating a list for all the dates for each ID, but I have thousands of rows and believe that will be very inefficient.

 

Expected Results:

 

Avg. Days in status by priority
Priority OrderedReady for Shipment
13 
2  
321
411
5  

 

Example summary table to show how i got the results above:

IDPriorityDateStatusDateDays
1082priority 11/15/2020ordered1/15/20203
1082  ready for shipment1/18/20202
1082priority 31/20/2020  1
1082  shipped1/21/20200
      
2045priority 31/18/2020ordered1/18/20202
2045  ready for shipment1/20/20201
2045priority 51/21/2020shipped 0
      
2061priority 41/19/2020ordered1/19/20201
2061  ready for shipment1/20/20201
2061  shipped1/21/20200

 

  • I was able to get it solved by appending the tables to get all the dates in one column, then adding calculated columns to find each change and the days between each change.

5 Replies

  • v-diye-msft's avatar
    v-diye-msft
    Icon for Community Support rankCommunity Support

    Hi PolarBear 

     

    Could you please kindly elaborate on how to get the Days in your expected table? not quite understand the calculation logic.

    • PolarBear's avatar
      PolarBear
      Icon for Helper I rankHelper I

      v-diye-msft ,

      ID 1082: Was in a prioriy 1, ordered status from 1/15/20. On 1/18/20, it changed to a prioiry 1, ready to ship status (I am calculating full days, 1/15 - 1/18 is 3 days). Then on 1/20, it changed to a priority 3, ready to ship status (1/18 - 1/20 is 2 days). Lastly, on 1/21, it shipped (effectively closing the ID)  (1/20 - 1/21 is 1 day) and  I don't want to count anything once the ID has ended (shipped).

      Thank you

       

  • PolarBear 

    Create a new column

    Diff = datediff([Date], maxx(filter(Table,[Id]=earlier([ID]) && [Date] <earlier([Date])),[Date]),day)

    • PolarBear's avatar
      PolarBear
      Icon for Helper I rankHelper I

      amitchandak ,

      Sorry, I'm not sure what to do with this. I tried putting it in one table and filtering the other table, but it returns all zeros.

      I have the calculations to calculate the number of days in each priority (it is below), but I don't know how to use it to also correlate with the dates in the second table. 

      Date Next =
      CALCULATE(
      MIN(Priority[Date]),
      ALLEXCEPT(Priority, Priority[ID]),
      Priority[Date] > EARLIER(Priority[Date] )
      )

       

      Date Diff in Days =
      IF(
      ISBLANK('Priority'[Date Next]),
      1,
      SUMX(
      FILTER(DateTable,
      DateTable[Date] >= 'Priority'[Date]
      && DateTable[Date] <= 'Priority'[Date Next]
      ),
      DateTable[IsWorkDay]
      ) + 0)
  • I was able to get it solved by appending the tables to get all the dates in one column, then adding calculated columns to find each change and the days between each change.