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

MIN date of a status dependent on a condition.

Hi,

 

I am trying to work out how to create a calucluated column that will provide a returned value of "In schedule" or Out of schedule" based on the week of the year for the start and finish date.

 

I have a table that has several date columns and a status column, and I can calculate the end date, but I am struggling to calculate the start date. I need to work out the MIN date of the order status change date to INPRG, but only when the order status does not change back to SCHEDULED, or WAPPR, or WSCH ( a quirk of our system that orders that require rescheduling need to be set to In Progress first to re-schedule)

 

My end goal is two measures, to distinct count orders that were completed in schedule, and out of schedule.

 

A sample dataset would look like the below, and the desired output is that order 1, and order 3 were completed out of schedule, and order 2 and order 4 were completed in schedule. Because I am working in an audit table, I get multiple rows of the same status when changes are made.

 

The logic in plain language would be -

Start date = the MIN status date for the last status change to INPRG before completion - this is where I am stuck

End date = the MAX status date for PCOMP ( I have used grouping and a seperate table to calculate this already)

 

In/Out  = If the start date week is less than the schedstart date week, or the end date week is greater than the schedfinish date week then return "OOS", otheriwse return "IS"

 

Any help would be greatly appreciated,

 

Craig

 

order_numschedstartschedfinishstatusstatus_dateIn/Out - (expected result)
115/05/202020/05/2020SCHEDULED20/03/2020OOS
116/05/202021/05/2020SCHEDULED21/03/2020OOS
116/05/202021/05/2020INPRG15/05/2020OOS
116/05/202021/05/2020INPRG16/05/2020OOS
116/05/202021/05/2020INPRG16/05/2020OOS
116/05/202021/05/2020PCOMP17/05/2020OOS
116/05/202021/05/2020CLOSE20/05/2020OOS
220/05/202022/05/2020SCHEDULED19/04/2020IS
220/05/202022/05/2020INPRG13/05/2020IS
220/05/202022/05/2020WSCH13/05/2020IS
220/05/202023/05/2020SCHEDULED13/05/2020IS
220/05/202023/05/2020INPRG21/05/2020IS
220/05/202023/05/2020PCOMP23/05/2020IS
220/05/202023/05/2020COMP26/05/2020IS
325/05/202027/05/2020SCHEDULED20/03/2020OOS
325/05/202027/05/2020INPRG21/03/2020OOS
325/05/202026/05/2020SCHEDULED20/03/2020OOS
325/05/202026/05/2020INPRG24/05/2020OOS
325/05/202026/05/2020PCOMP26/05/2020OOS
325/05/202027/05/2020COMP28/05/2020OOS
325/05/202027/05/2020CLOSE28/05/2020OOS
420/05/202022/05/2020SCHEDULED19/04/2020IS
420/05/202022/05/2020INPRG13/05/2020IS
420/05/202022/05/2020WSCH13/05/2020IS
420/05/202023/05/2020SCHEDULED13/05/2020IS
420/05/202023/05/2020INPRG21/05/2020IS
420/05/202023/05/2020WAPPR22/05/2020IS
401/06/202003/06/2020WSCH22/05/2020IS
431/05/202003/06/2020SCHEDULED25/05/2020IS
431/05/202003/06/2020INPRG31/05/2020IS
431/05/202003/06/2020PCOMP05/06/2020IS
431/05/202003/06/2020COMP05/06/2020IS
431/05/202003/06/2020CLOSE10/06/2020IS

 

(expectd results  if this helps  )

Order 1 start date = 15/05/2020 end date = 17/05/2020

Order 2 start date = 21/05/2020 end date = 23/05/2020

Order 3 start date = 24/05/2020 end date = 26/05/2020

Order 4 start date = 31/05/2020 end date = 05/06/2020

1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

@NZCraig 

Please try to create a column

Column = 
VAR mindate=MAXX(FILTER(Sheet4,Sheet4[order_num]=EARLIER(Sheet4[order_num])&&Sheet4[status]="INPRG"),Sheet4[status_date])
VAR maxdate=MAXX(FILTER(Sheet4,Sheet4[order_num]=EARLIER(Sheet4[order_num])&&Sheet4[status]="PCOMP"),Sheet4[status_date])
return if(WEEKNUM(mindate)<WEEKNUM(Sheet4[schedstart])||WEEKNUM(maxdate)>WEEKNUM(Sheet4[schedfinish]),"OOS","IS")

1.PNG

However the output is different from what you expected.

Order 1

schedulestartdate 2020/5/16, startdate 2020/5/15 and week is not less than schedulestartedate

schedulefinishedate 2020/5/21, enddate 2020/5/17 and week is not greater than schedulefinishdate.

That's why the output is IS not OOS.

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

4 REPLIES 4
ryan_mayu
Super User
Super User

@NZCraig 

Please try to create a column

Column = 
VAR mindate=MAXX(FILTER(Sheet4,Sheet4[order_num]=EARLIER(Sheet4[order_num])&&Sheet4[status]="INPRG"),Sheet4[status_date])
VAR maxdate=MAXX(FILTER(Sheet4,Sheet4[order_num]=EARLIER(Sheet4[order_num])&&Sheet4[status]="PCOMP"),Sheet4[status_date])
return if(WEEKNUM(mindate)<WEEKNUM(Sheet4[schedstart])||WEEKNUM(maxdate)>WEEKNUM(Sheet4[schedfinish]),"OOS","IS")

1.PNG

However the output is different from what you expected.

Order 1

schedulestartdate 2020/5/16, startdate 2020/5/15 and week is not less than schedulestartedate

schedulefinishedate 2020/5/21, enddate 2020/5/17 and week is not greater than schedulefinishdate.

That's why the output is IS not OOS.

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thanks Ryan,

 

When combined with a new table I found within the database, this works for me. Appreciate you help and guidance with this.

 

Cheers


Craig

lbendlin
Super User
Super User

Your status_date column is ambiguous. For example order 2 had three events on 13/05/2020,  and the date granularity on that colums could impact the logic you want to implement. Is there another column for the event id ? or maybe the Status_date column is actually datetime?

 Hi,

 

I didn't include all columns in the table, there is another column that is date/time that is a transaction timestamp column called eaudittimestamp. I may have thought of another to solve this problem today, but am just working through testing it now.

 

Thanks

Craig

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.