John Simons wrote...
....
scenarios possible, we needed to compile four separate equations: month 1,
months 2 - 12, months 13 - 24, and months 25+. The equation for months 25+
converted easily (only 6 nested IF statements!) so I did not include them
here. I am aware that Excel does not have the DATEDIF function, but I can
get around that easily (only applicable for the first month anyway). Here
are the equations direct from Lotus 1-2-3:
Month 1:
@IF(L14<0,L14+N14,@IF((@DATEDIF(C$4,E14,"m"))<1,(H14-J14),@IF(F14<T$9,0,
@IF((F14-G14)>=T$9,0,@IF((@DATEDIF(C$4,E14,"m"))<1,(H14-J14),@IF(T$8=L$8,
(L14/@IF(F14<=F$1,+F14,@IF(@YEAR(@DATEVALUE(+D14))+1900=T$8,@IF(T$9<F$1,F$1,
@IF(G14-F14>=F$1,F$1,(13-(@MONTH(+D14))))),F$1))),@IF(T$9<=F14,@IF(T$8=N$8,
N14/@IF(+H14-I14-K14=N14,F14,@IF(@YEAR(@DATEVALUE(+D14))+1900=T$8,
(13-(@MONTH(+D14))),@IF(@YEAR(@DATEVALUE(+E14))+1900=T$8,(@MONTH(+E14)),
@IF(F14-F$1>12,12,F14-F$1)))),0),0)))))))
....
First simplification: your initial test can be separated.
=(L14<0)*(L14+N14)+(L14>=0)*IF(DATEDIF(C$4,E14,"m")<1,...)
Next, there's this mishmash.
IF(DATEDIF(C$4,E14,"m")<1,
H14-J14,
IF(F14<T$9,
0,
IF(F14-G14>=T$9,
0,
IF(DATEDIF(C$4,E14,"m")<1,
H14-J14,
IF(T$8=L$8,
This is an error. The first DATEDIF call is identical to the second
DATEDIF call, so the second one is NECESSARILY redundant. The only way
to get to the second DATEDIF call is if the first DATEDIF call returns
a number >= 1, in which case the second one must NECESSARILY be false.
So the second 'IF(DATEDIF(...)<1,H14-J14,' can be deleted. Then merge
the two conditions that result in 0 and use their complement. So
IF(DATEDIF(C$4,E14,"m")<1,
H14-J14,
AND(F14>=T$9,F14-G14<T$9)*IF(T$8=L$8,
The first denominator expression,
IF(F14<=F$1,
F14,
IF(YEAR(DATEVALUE(D14))+1900=T$8,
IF(T$9<F$1,
F$1,
IF(G14-F14>=F$1,
F$1,
13-MONTH(D14)
)
),
F$1
)
)
evaluates to F1 in 3 different cases, but to F14 or 13-MONTH(D14) in
only one case, respectively. Simplify.
IF(F14<F$1,
F14,
IF((YEAR(--D14)=T$8)*((F$1<=T$9)+(G14-F14<F$1)),
13-MONTH(D14),
F$1
)
)
Note that Excel's YEAR function ALWAYS returns 4-digit years, so you
need to delete the '+1900' terms from ALL formulas. This is a real
PITA, but it's just one of those things Excel's 123 converter doesn't
catch. Also note that DATEVALUE is redundant in Excel - any string
representation of a number or a date in long or short date format per
Windows Regional Settings can be converted into numeric or date serial
value just by using it as an arithmetic operand. The '--' are two unary
minuses in sequence.
The final expression evaluates to 0 in 2 cases. Merge them and use
their complement. So replace
IF(T$9<=F14,
IF(T$8=N$8,
N14/IF(H14-I14-K14=N14,
F14,
IF(YEAR(DATEVALUE(D14))+1900=T$8,
13-MONTH(D14),
IF(YEAR(DATEVALUE(E14))+1900=T$8,
MONTH(E14),
IF(F14-F$1>12,
12,
F14-F$1
)
)
)
),
0
),
0
)
with
(T$9<=F14)*(T$8=N$8)*N14/IF(H14-I14-K14=N14,
F14,
IF(YEAR(--D14)=T$8,
13-MONTH(D14),
IF(YEAR(--E14)=T$8,
MONTH(E14),
MIN(F14-F$1,12)
)
)
)
That makes the entire equivalent Excel formula
=(L14<0)*(L14+N14)+(L14>=0)*IF(DATEDIF(C$4,E14,"m")<1,H14-J14,
AND(F14>=T$9,F14-G14<T$9)*IF(T$8=L$8,L14/IF(F14<F$1,F14,
IF((YEAR(--D14)=T$8)*((F$1<=T$9)+(G14-F14<F$1)),13-MONTH(D14),F$1)),
(T$9<=F14)*(T$8=N$8)*N14/IF(H14-I14-K14=N14,F14,IF(YEAR(--D14)=T$8,
13-MONTH(D14),IF(YEAR(--E14)=T$8,MONTH(E14),MIN(F14-F$1,12))))))
Apply similar simplifications to your other formulas.