Forum Discussion

zaidmasad's avatar
zaidmasad
Helper III
8 years ago
Solved

Calculating the Transit time between two dates excluding holidays and situational dates

Hello,

 

I have a set of data, and i want to calculate the transit time excluding the situational dates and holidays for the origin. I have made three tables one for the situational dates, one for the holidays and a calendar table as below:

Situational Dates:

Weekends:

Calendar:

 

I have this code, but it doesnt take into consideration what days for each origin are the weekends:

 

Detail = 
var calendarTable= CALENDAR([Start Date],[End Date])
var exceptDate=CALCULATETABLE(VALUES(Sheet3[situation Date]),FILTER(ALL(Sheet3),[Entity]=EARLIER(Sheet2[Origin Entity])||[Entity]=EARLIER(Sheet2[Destination Entity])))
var filtered=ADDCOLUMNS(EXCEPT(calendarTable,exceptDate),"Day Of Week",WEEKDAY([Date],1))
return
CONCATENATEX(FILTER(filtered,[Day Of Week]<>1&&[Day Of Week]<>7),[Date],",")

Count = 
var calendarTable= CALENDAR([Start Date],[End Date])
var exceptDate=CALCULATETABLE(VALUES(Sheet3[situation Date]),FILTER(ALL(Sheet3),[Entity]=EARLIER(Sheet2[Origin Entity])||[Entity]=EARLIER(Sheet2[Destination Entity])))
var filtered=ADDCOLUMNS(EXCEPT(calendarTable,exceptDate),"Day Of Week",WEEKDAY([Date],1))
return
COUNTROWS(FILTER(filtered,[Day Of Week]<>1&&[Day Of Week]<>7))

 

My data looks like the below:

 

AWBOrigin EntityDestination EntityStart DateEnd Date
IMAE10002RUHDXB9/17/20179/17/2017
IMAE10006LONDXB7/3/20177/3/2017
IMAE10018MILDXB7/3/20177/4/2017
IMAE10027LONDXB9/18/20179/19/2017
IMAE10028HAXDXB9/18/20179/19/2017

 

Thank you

  • Hello Anonymous

     

    I have made some changes on the code now and its working well. but I am facing a problem now when one of the dates is blank or the start date is after the end date.

     

    Can this problem be fixed?

     

    Thank you

     

    The new code is as below:

     

    T1 = var calendarTable= CALENDAR([CreatedOn],[CollectionInProgressDate_UTC])
    var exceptDate=CALCULATETABLE(VALUES('Situational Holidays'[situationDate]),FILTER(ALL('Situational Holidays'),[Entity]=EARLIER('Dates'[ShipperEntity])))
    var filtered=ADDCOLUMNS(EXCEPT(calendarTable,exceptDate),"Day Of Week",WEEKDAY([Date],1))
    return
    COUNTROWS(FILTER(filtered,[Day Of Week]<> 'Dates'[First weekend] && [Day Of Week]<>'Dates'[secound weekend]))-1

     

11 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    zaidmasad,

    In your Weekends table, do you mean that for entity ACC, the weekends are Sunday and Monday? If so, what are the weekends for the Origin Entity and Destination Entity(RUH,LON, MIL,LON,HAX,DXB)? And do you want to exclude weekends for Origin Entity or Destination Entity?

    We will appreciate that if you can share the complete data of these tables. You can upload the excel file to OneDrive, and post shared link of the excel file here.

    Regards,
    Lydia

    • zaidmasad's avatar
      zaidmasad
      Helper III

      hi Anonymous,

       

      Yes, for example in DXB the weekends are friday and saturday, for LON its Saturday and Sunday.

      The weekends should be excluded based on the origin entity. it is restricted to open Onedrive in our company so he weekends for the requested entities are as below:

       

      Entity   1st weekend 2nd weekend

      MIL60
      LON60
      DXB56
      RUH56
      HAX56

       

      The tables I have and their fields are as the following:

      • Anonymous's avatar
        Anonymous
        Not applicable

        zaidmasad,

        I send you a Private message, please check it.

        Regards,
        Lydia