Search code examples
if-statementgoogle-sheetslambdanested-ifgoogle-sheets-formula

GOOGLE SHEETS - Arrayformula for duration between 2 datetime stamps ignoring weekends and our of hours time


I'm trying to work out the duration of 2 date/time stamps, ignoring out-of-hours and weekends. I have a formula that does individual durations (Column D) but when I try turning it into an array formula (Column E) it doesn't seem to work. I'm sure I have something slightly off and that is what is causing the issue.

I would greatly appreciate somebody taking a look at it.

Many thanks

https://docs.google.com/spreadsheets/d/1NwDtnB9tyiJOAZHOKL7aSQnaMc4LpPIm7mGffPRKKcc/edit?usp=sharing


Solution

  • use:

    =ARRAYFORMULA(IF(B4:B=TRUE, MAP(A4:A100, C4:C100, 
     LAMBDA(A,C, (NETWORKDAYS(A,C)-1)*($C$1-$B$1)+IF(NETWORKDAYS(C,C),
     MEDIAN(MOD(C,1),$C$1,$B$1),$C$1)-MEDIAN(NETWORKDAYS(A,A)*MOD(A,1),$C$1,$B$1))), ))
    

    enter image description here