Forum Discussion

RobertReeves's avatar
RobertReeves
Frequent Visitor
3 years ago

Need Difference between dates minus weekends and holidays

I am creating a report that needs to display the delta between 2 dates, minus weekends and holidays. I tried network days, but for some reason BI would not recognize NETWORKDAYS.

 

We used to accomplish this task in Excel by using =networkdays(f2,g2)-1 and then changing any 3s to a 2 for a month that has a holiday. 

 

I have a date table and a holiday table. The date table is linked to the main table by the date (G). I have created a column in the holiday table with just the month number and linked that with a month number in the main table.

Is there a way to use this to get to the final outcome needed below?

FGDelta F & GAfter FormulaFinal Outcome 
12/23/2022 19:2612/28/2022532
12/16/2022 19:3712/17/2022100
12/21/2022 17:1612/23/2022222
12/22/2022 21:0612/23/2022111
12/23/2022 12:1712/27/2022422
12/2/2022 20:4812/5/2022311
12/7/2022 19:2612/9/2022222
12/8/2022 19:2212/12/2022422
12/27/2022 18:4512/29/2022222
12/19/2022 21:1212/20/2022111
12/20/2022 11:4712/22/2022222
12/22/2022 19:2012/27/2022532
12/21/2022 21:2812/22/2022111
12/23/2022 12:2812/28/2022532

7 Replies

  • Yes, you can use DAX to calculate the final outcome needed. You can create a calculated column using DAX to determine the number of workdays between two dates, excluding weekends and holidays.

  • Here is an example of a DAX formula that could be used for this calculation:

    =IF(ISBLANK([Delta F & G]),BLANK(),IF(MONTH(G) = RELATED(Holiday[Month Number]), [Delta F & G] - 2, [Delta F & G] -1))

     

    Assuming that the date table is linked to the main table by the date column (G), the holiday table is linked to the main table by the month number column, and the "Delta F & G" column is the number of days between the two dates.

  • The above formula first checks if the "Delta F & G" column is blank. If it is, it returns a blank. If not, it checks if the month of the date in column G is the same as the related month number in the holiday table. If it is, it subtracts 2 from the "Delta F & G" value. If not, it subtracts 1.

     

    This will give you the "Final Outcome" column as in the example you provided.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you!

  • Could you just use index columns in your calendar?

     

    Add a weekday name column and filter out Sat and Sunday.

     

    Import a holiday table and merge it to your calendar. (you can link to an online or a company one) Then just filter by entry = "null"

     

    Add 2 index columns one starting at 0 the next starting at 1.

     

    Merge the query to itself with the first column being index starting at 0 then starting at 1 and add the date column and label it previous date.

     

    Then you will end up with both dates in the same row and can add whatever calculated column you would like to use on the two dates.