Forum Discussion

JagThripp's avatar
JagThripp
Frequent Visitor
8 years ago
Solved

Count days between two dates excluding weekends and holidays

I have tried searching this forum but as I am so new to Power BI I have only confused my self even more, I apologize for this.

 

I have logged and closed date fields in a table that I am trying to get the number of working days between (if no closed date then use Now()), also I have a holidays table, that has the holidays pertinant to our locale by year.

 

Holidays

As I have seen in a few of the posts on this forum, I am trying to evaluate the number of days between the OPENED and RESOLVED dates. 

These two fields are formatted as yyyy-mm-dd hh:mm:ss in 24 hour format.

 

 

Which are imported CSV files.

 

It would be good if a year can be identified from the OPENED date field to use on the holidays table so the correct dates are used.

 

Calculations should only be used if the RESOLVED date is NULL.

I am not sure if all of my desires are even achievable, so thanks to you all in advance.

5 Replies

  • ImkeF's avatar
    ImkeF
    Icon for Community Champion rankCommunity Champion

    This would be easiest to show if you could upload some sample data, please.

    • JagThripp's avatar
      JagThripp
      Frequent Visitor

      Here is a sample of data, I have trimmed out some unnecessary columns.

       

      NumberOpenedResolvedPriorityStatusType
      REQ096259809/05/18 18:04 4 - LowAcknowledgedStandard
      REQ096202908/05/18 11:11 4 - LowAcknowledgedNon-Standard
      REQ096135504/05/18 09:5304/05/18 10:044 - LowResolvedStandard
      REQ096118503/05/18 14:01 4 - LowIn ProgressStandard
      REQ096023230/04/18 12:4102/05/18 09:234 - LowResolvedStandard
      REQ095962626/04/18 12:56 4 - LowAwaiting CustomerNon-Standard
      REQ095955826/04/18 11:0602/05/18 11:264 - LowResolvedStandard
      REQ095948526/04/18 09:2104/05/18 12:064 - LowResolvedStandard
      REQ095946126/04/18 07:5726/04/18 08:264 - LowClosedNon-Standard
      REQ095935424/04/18 14:3130/04/18 09:523 - MediumResolvedStandard
      REQ095935324/04/18 14:3102/05/18 11:304 - LowResolvedStandard
      REQ095905023/04/18 15:3630/04/18 10:034 - LowResolvedStandard
      REQ095902723/04/18 14:5327/04/18 13:414 - LowResolvedStandard
      REQ095883023/04/18 09:2101/05/18 12:194 - LowResolvedStandard
      REQ095854120/04/18 10:5926/04/18 08:084 - LowClosedStandard
      REQ095847020/04/18 08:5520/04/18 11:054 - LowClosedStandard
      REQ095846920/04/18 08:5426/04/18 08:094 - LowClosedStandard
      REQ095846820/04/18 08:5326/04/18 08:104 - LowClosedStandard
      REQ095846720/04/18 08:5326/04/18 08:084 - LowClosedStandard
      REQ095846620/04/18 08:5120/04/18 11:014 - LowClosedStandard
      REQ095831619/04/18 14:0601/05/18 12:314 - LowResolvedStandard
      REQ095830819/04/18 13:5501/05/18 12:324 - LowResolvedNon-Standard
      REQ095830619/04/18 13:5219/04/18 13:544 - LowClosedStandard
      REQ095829719/04/18 13:4819/04/18 13:524 - LowClosedStandard
      REQ095797518/04/18 12:3104/05/18 09:424 - LowResolvedStandard
      REQ095793418/04/18 11:3620/04/18 09:544 - LowClosedStandard
      REQ095783918/04/18 09:14 4 - LowAcknowledgedNon-Standard
      REQ095751117/04/18 08:5620/04/18 09:484 - LowClosedStandard
      REQ095687813/04/18 12:2624/04/18 09:334 - LowClosedNon-Standard
      REQ095576209/04/18 16:1612/04/18 08:054 - LowClosedStandard
      REQ095572209/04/18 15:1616/04/18 09:444 - LowClosedStandard
      REQ095571509/04/18 15:0612/04/18 08:034 - LowClosedStandard
      REQ095945909/04/18 11:5026/04/18 09:363 - MediumClosedNon-Standard
      REQ095570406/04/18 11:54 3 - MediumIn ProgressNon-Standard
      REQ095502605/04/18 15:5423/04/18 10:594 - LowClosedStandard
      REQ095486605/04/18 11:0111/04/18 14:404 - LowClosedNon-Standard
      REQ095563304/04/18 14:50 4 - LowIn ProgressNon-Standard
      REQ095466304/04/18 13:5111/04/18 14:594 - LowClosedStandard
      REQ095466204/04/18 13:5111/04/18 14:584 - LowClosedStandard
      REQ095463004/04/18 13:0609/04/18 11:274 - LowClosedStandard
      REQ095575704/04/18 13:05 4 - LowAwaiting CustomerNon-Standard
      REQ095562404/04/18 12:55 4 - LowIn ProgressNon-Standard
      REQ095560804/04/18 12:5116/04/18 13:294 - LowClosedNon-Standard
      REQ095560304/04/18 12:49 4 - LowAcknowledgedNon-Standard
      REQ095667104/04/18 07:5120/04/18 15:084 - LowClosedStandard
      REQ095433729/03/18 16:46 4 - LowIn ProgressNon-Standard
      REQ095480229/03/18 10:3811/04/18 14:563 - MediumClosedStandard
      REQ095400028/03/18 14:1609/04/18 08:364 - LowClosedStandard
      REQ095398628/03/18 13:3626/04/18 13:034 - LowClosedStandard
      REQ095386928/03/18 09:41 4 - LowIn ProgressNon-Standard
      REQ095369727/03/18 14:3111/04/18 15:004 - LowClosedStandard
      REQ095369227/03/18 14:2209/04/18 13:274 - LowClosedStandard
      REQ095343626/03/18 15:3629/03/18 10:294 - LowClosedNon-Standard
      REQ095335126/03/18 13:0613/04/18 11:444 - LowClosedStandard
      REQ095328126/03/18 10:56 4 - LowIn ProgressNon-Standard
      REQ095327926/03/18 10:5616/04/18 16:074 - LowClosedStandard
      REQ095301323/03/18 13:2126/03/18 12:004 - LowClosedStandard
      REQ095300323/03/18 12:5126/03/18 09:004 - LowClosedStandard
      REQ095287922/03/18 17:5113/04/18 11:384 - LowClosedStandard
  • Hi JagThripp,

     

    In my opinion, to count working days between two dates excluding weekends and holidays. We need to create calendar table to mark the holidays. So that we can refer to this calendar table and exclude the weekends and holidays in your Fact table. Something like:

     

    https://community.powerbi.com/t5/Desktop/calculate-number-of-working-days-between-2-dates/m-p/55456/highlight/true#M22521

     

    https://community.powerbi.com/t5/Desktop/Calculating-number-of-days-between-two-dates/m-p/50073/highlight/true#M20013

     

    With current detail Holidays table, it is hard to create relationship between it with your Fact table since the holidays in each year are separated in multiple columns.

     

    So in your scenario, I think you can go to Edit Queries. Duplicate your Holidays table to multiple ones and for each one keep one year column and remove others. Then you can Append these new queries to make all the dates in one same column. By doing this, you can create a new Holidays table with all the holidays in one same column.

     

    Thanks,
    Xi Jin.

    • JagThripp's avatar
      JagThripp
      Frequent Visitor

      Hi Xin,

       

      I have modified the holidays table to be one column of dates formatted as dd/mm/yy.

       

      What I seem to be missing is how this helps to calculate the number of "valid working" days between the created date and "NOW()".

       

      I have looked at the examples you posted, but with my data I fail to see how to apply this methodology.

       

      Jag

       

      • PowerBInewb's avatar
        PowerBInewb
        Frequent Visitor

        Jag,

         

        I am in the same boat, did you ever have any success with this?

         

        Thanks!