Forum Discussion

lennox25's avatar
lennox25
Icon for Post Patron rankPost Patron
4 years ago
Solved

How to calculate date difference excluding weekends - Always a start date but some end dates blank

Hi - I wonder if anyone can help. I need to calculate the date difference excluding weekends. There is always a start date but sometimes the task has not been completed so there is no end date.

 

Before I was asked to exclude weekends my calculation was  - 

Days taken to Complete = if(ISBLANK('Tracker'[Date of first contact ]),BLANK()
, if(ISBLANK('Tracker'[Date decision confirmed ]), BLANK()
, DATEDIFF('Tracker'[Date of first contact],'Tracker'[Date decision confirmed], DAY)
)
)
 
Does anyone know if this formula can be adjusted?
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi lennox25 ,

    I have created a simple sample, please refer to it to see if it helps you.

    Replace a blank date with today's date.

    Click Trandform data>>Trandform>>Replace values.

    Then change the column.

    = Table.ReplaceValue(#"Changed Type",null,DateTime.LocalNow() ,Replacer.ReplaceValue,{"end date"})

    Then the null value will  be filled with present time.

    Then create a measure by using Greg_Deckler 's Net Work Days .

    NetWorkDays = 
    VAR Calendar1 = CALENDAR(MAX(Sheet3[start date]),max(Sheet3[end date]))
    VAR Calendar2 = ADDCOLUMNS(Calendar1,"WeekDay",WEEKDAY([Date],2))
    RETURN COUNTX(FILTER(Calendar2,[WeekDay]<6),[Date])

    If I have misunderstood your meaning, please provide some sample data and desired output.

     

    Best Regards

    Community Support Team _ Polly

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

11 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi lennox25 ,

    I have created a simple sample, please refer to it to see if it helps you.

    Replace a blank date with today's date.

    Click Trandform data>>Trandform>>Replace values.

    Then change the column.

    = Table.ReplaceValue(#"Changed Type",null,DateTime.LocalNow() ,Replacer.ReplaceValue,{"end date"})

    Then the null value will  be filled with present time.

    Then create a measure by using Greg_Deckler 's Net Work Days .

    NetWorkDays = 
    VAR Calendar1 = CALENDAR(MAX(Sheet3[start date]),max(Sheet3[end date]))
    VAR Calendar2 = ADDCOLUMNS(Calendar1,"WeekDay",WEEKDAY([Date],2))
    RETURN COUNTX(FILTER(Calendar2,[WeekDay]<6),[Date])

    If I have misunderstood your meaning, please provide some sample data and desired output.

     

    Best Regards

    Community Support Team _ Polly

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • lennox25 , a new column like

     

    COUNTROWS(FILTER(ADDCOLUMNS(CALENDAR(Table[Date of first contact],Table[Date decision confirmed]),"WorkDay", if(WEEKDAY([Date],2) <6,1,0)),[WorkDay] =1))

     

    How to calculate Business Days/ Workdays, with or without date table: https://youtu.be/Qv4wT8_P-AA

    • lennox25's avatar
      lennox25
      Icon for Post Patron rankPost Patron

      amitchandak Thank you - via a search I already tried this but as the end date is blank in a few rows it shows an error. Any idea how to factor this in? TIA

       

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

        lennox25 VAR __EndDate = IF(ISBLANK(...), TODAY(), ...). 

         

        Basically just substitute today's date if it is blank.

    • lennox25's avatar
      lennox25
      Icon for Post Patron rankPost Patron

      HI amitchandak I already have differnce between the dates as formua shown in my original question. The formula you provided works perfectly providing there are no blank dates. There are blank dates (end dates) so now the formula shows as error. I have a standard (company) date table and have brought in an excel spreadsheet that gets updated daily  -which contains all the start and end dates.