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

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

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

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.