Two things: An extension to SGIII's formula to include a maximum value (2h) for the calculation to which it's applied, and a closer look at the calculation itself.
From SG's post:
=MAX(DURATION(0),existing expression)
Revised: Above formula enclosed in MIN(value 1,value 2)
=MIN(MAX(DURATION(0),existing expression),DURATION(,,2))
The existing formula from your second screen shot (I've used the address of cell B2 in place of the name in your screen shot, and shortened the name of the Admin table in references to the cell on that table to make the formula more compact here.):
C2: =MAX(DURATION(0),IF(B2≥TIME(5,5,0),IF(ISBLANK(Ad::$E$1)-ISBLANK(B2), ISBLANK(Ad::$E$1)-ISBLANK(B2), (Ad::$E$1)-(B2)))
Here's the same formula broken into parts, and with the parts labelled:
1: =MAX(
2: DURATION(0),
3: IF(
4: B2≥TIME(5,5,0),
5: IF(
6: ISBLANK(Ad::$E$1)-ISBLANK(B2),
7: ISBLANK(Ad::$E$1)-ISBLANK(B2),
8: Ad::$E$1-B2
9: )
A: )
B: )
MAX(value 1, value 2)
Line 2 is value 1 for this function, Everything from line 3 to line A is value 2, line B is the closing bracket for MAX.
No problems with line 2.
3: IF(test, do if TRUE, do if FALSE)
Line 4 is the test for this IF. It compares the Date/Time value in B2 with the Date/Time value constructed by the TIME() function. This comparison will always return true here for the reasons discussed in my previous post.
Lines 5 to 9 is the do if true part of this IF. There is no do if FALSE part.
Line A is the closing bracket for the IF at line 3.
5: A second IF(test, do if TRUE, do if FALSE) to be done only if th test for the first IF returns TRUE
6: the test for this IF
ISBLANK returns the Boolean value TRUE if the tested cell is empty and FALSE if the cell contains data of any type.
The result of the second test is subtracted from the result of the first, with four possible results:
TRUE - TRUE (both cells empty), FALSE - FALSE (both cells have data) Both these cases will return a result of zero.
TRUE - FALSE (data in E1, no data in B2) Returns result of 1
FALSE - TRUE (data in B2, no data in E1) Returns result of -1
All four cases will also produce a blue warning triangle warning that "The formula uses a Boolean in place of a number."
IF interprets any number other than zero as TRUE, so if one tested cell is empty and the other has data, IF moves on to 'do if TRUE (line 7); if neither has data or if both have data, IF moves on to do if FALSE (line 8).
7: do if TRUE
Done only if the result of the test was 'true' Since this expression is the same as the test expression, it's result will always be 1 or -1.
8: do if FALSE
Done only if the test result was 'false'.
The expression subtracts the contents of B2 from the contents of Ad::E1.
9: Closing bracket for the second IF. Result is passed back to the first IF.
A: Closing bracket for the first IF. Result is passed back to MAX
B: Closing bracket for MAX. Result is returned to cell C2.
Does this formula give the results you are expecting (disregarding the return of values greater than 2h for the current version)? If not, do you see here what part needs to be changed to make it return the expected results?
Regards,
Barry