Forum Discussion

learner03's avatar
learner03
Post Partisan
4 years ago
Solved

Measure to get time/date

I have a column as Job Create time eg 14/01/2022 12:03:45 AM. I want to create a measure that shows the Job Close time as 48 hours plus to the Job Create time.  But, if there is a weekend or public h...
  • ryan_mayu's avatar
    ryan_mayu
    4 years ago

    learner03 

    pls try this

    Column = 
    VAR next=minx(FILTER('Table (2)','Table'[create time]<'Table (2)'[DATE] && 'Table (2)'[IF WORKDAY]="Yes"),'Table (2)'[DATE])
    return minx(FILTER('Table (2)',next<'Table (2)'[DATE] && 'Table (2)'[IF WORKDAY]="Yes"),'Table (2)'[DATE])+mod('Table'[create time],1)

    pls see the attachment below

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi~ learner03 

     

    According to your description,I created the file as follows:

    We first need to create a table of public holidays,these data can be easily obtained from the Web source.I have created a simple table here, you can extend it as needed.

    Then we need a calendar to filter out which dates are working days:

     

    Table1 = CALENDAR(date(2022,01,01), date(2022,12,31)) 
    Holiday = LOOKUPVALUE('PublicHolidayTable'[Name],PublicHolidayTable[Date],'Table1'[Date])
    WeekDay = WEEKDAY('Table1'[Date],2)
    Working Day = 
    SWITCH (
    TRUE (),
    ISBLANK ('Table1'[Holiday])
    && 'Table1'[WeekDay] < 6, "1",
    ISBLANK ('Table1'[Holiday])
    && 'Table1'[WeekDay] >= 6, "0",
    "0"
    )

     

    the third table:

    Please create a measure:

     

    JobEndTime = 
    VAR _time = TIMEVALUE(FORMAT(MAX(Table2[JobCreateTime]),"hh:mm:ss"))
    VAR _table = TOPN(2,FILTER('Table1','Table1'[Date]>MAX(Table2[JobCreateTime])&&'Table1'[Working Day]="1"),'Table1'[Date],ASC)
    VAR _newDate = MAXX(_table,[Date]) +_time
    return 
    _newDate

     

    And the result should look like this.

    Hope this helps~

     

    Best Regards,

    Community Support Team _ Gao

     

    If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!