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
PolarBear
Helper I
Helper I

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

 

1 ACCEPTED SOLUTION
PolarBear
Helper I
Helper I

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.

View solution in original post

5 REPLIES 5
PolarBear
Helper I
Helper I

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.

v-diye-msft
Community Support
Community Support

Hi @PolarBear 

 

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

007.PNG

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.

@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

 

amitchandak
Super User
Super User

@PolarBear 

Create a new column

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

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

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.