IF dates

BrutalLogiC

Active Member
Joined
Feb 26, 2006
Messages
274
Office Version
  1. 365
Platform
  1. Windows
Hey I'm struggling with a formula for cells in yellow to calculate the monthly values for a contract which keeps changing its value. Contract started 30-Jan-24 with an annualised value of 15,000 then this annualised value was replaced/updated 3 times before the contract came to an end on 2-Aug-24.

H6:S6 in grey are just my manual calculations to to show what values should be.

For months where there is no variation change in value I am expecting the result to be the latest annualised value divided by 12, e.g. for April the value should 1/12th of variation 2 annualised value.

For months where there is a change in value (March and June) or a partial month (e.g. January and August where there are only 2 days) the value should be calculated based on the corresponding annualised value divided by 365.

monthly value formula.xlsx
CDEFGHIJKLMNOPQRST
2Contract phaseStart date of contract phaseAnnualised valueDaily valueJan-24Feb-24Mar-24Apr-24May-24Jun-24Jul-24Aug-24Sep-24Oct-24Nov-24Dec-24Total
3Start30-Jan-2415,000410
4Variation 11-Feb-2412,00033
5Variation 25-Mar-2416,00044Jan-24Feb-24Mar-24Apr-24May-24Jun-24Jul-24Aug-24Sep-24Oct-24Nov-24Dec-24Total
6Variation 328-Jun-2420,00055Values should be:821,0001,3151,3331,3331,3481,6671108,188
7
8End date2-Aug-24
Sheet2
Cell Formulas
RangeFormula
T3,T6T3=SUM(H3:S3)
F3:F6F3=E3/365
H6H6=E3/365*2
I6I6=E4/12
J6J6=(E5/365*27)+(E4/365*4)
K6K6=E5/12
L6L6=E5/12
M6M6=E5/365*27+E6/365*3
N6N6=E6/12
O6O6=E6/365*2
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hello, the following is an attempt to address the question - not very elegant but hopefully will do the trick:

Excel Formula:
=LET(
a,D3:D6,
b,VSTACK(DROP(a,1),D8+1),
c,H2:S2,
d,F3:F6,
e,E3:E6,
seq,SEQUENCE(ROWS(a)),
days,EOMONTH(+c,0)-c+1,
f,DROP(REDUCE("",seq,LAMBDA(x,y,VSTACK(x,BYCOL(c,LAMBDA(z,MAX(MIN(EOMONTH(z,0),INDEX(b,y,0)-1)-MAX(z,INDEX(a,y,0))+1,0)))))),1),
BYCOL(IF(days=f,e/12,f*e/365),LAMBDA(x,SUM(x))))
 
Upvote 0
Another approach:
Excel Formula:
=LET(e,$D$8,v,$D$3:$D$8,r,$D$3:$F$8,a,H2,b,EOMONTH(a,0),c,IFERROR(LOOKUP(a,v),e),d,LOOKUP(b,v),
IF(AND(a>=c,b>=d,c=d),VLOOKUP(d,r,2,0)/12,((d=e)+d-a)*VLOOKUP(c,r,3,0)+(b-d+1)*VLOOKUP(d,r,3,0)))
Prerequisites: there should be no more than 1 variation per month; Annualized value and Daily value cells for the End date should be empty or set to 0.
 
Upvote 0
Hello, the following is an attempt to address the question - not very elegant but hopefully will do the trick:

Excel Formula:
=LET(
a,D3:D6,
b,VSTACK(DROP(a,1),D8+1),
c,H2:S2,
d,F3:F6,
e,E3:E6,
seq,SEQUENCE(ROWS(a)),
days,EOMONTH(+c,0)-c+1,
f,DROP(REDUCE("",seq,LAMBDA(x,y,VSTACK(x,BYCOL(c,LAMBDA(z,MAX(MIN(EOMONTH(z,0),INDEX(b,y,0)-1)-MAX(z,INDEX(a,y,0))+1,0)))))),1),
BYCOL(IF(days=f,e/12,f*e/365),LAMBDA(x,SUM(x))))
thanks for your reply, unfortunately I get a Spill error when trying this!
 
Upvote 0
Another approach:
Excel Formula:
=LET(e,$D$8,v,$D$3:$D$8,r,$D$3:$F$8,a,H2,b,EOMONTH(a,0),c,IFERROR(LOOKUP(a,v),e),d,LOOKUP(b,v),
IF(AND(a>=c,b>=d,c=d),VLOOKUP(d,r,2,0)/12,((d=e)+d-a)*VLOOKUP(c,r,3,0)+(b-d+1)*VLOOKUP(d,r,3,0)))
Prerequisites: there should be no more than 1 variation per month; Annualized value and Daily value cells for the End date should be empty or set to 0.
many thanks this works, is it possible to adapt the formula to suit the data arranged in columns? e.g. to fit the below arrangement

monthly value formula.xlsx
BCDEFGHIJKLMNO
13StartVariation 1Variation 2Variation 3
14ReferenceStartAnnualised valueDaily valueV1 startAnnualised valueDaily valueV2 startAnnualised valueDaily valueV3 startAnnualised valueDaily valueEnd date
15Contract A30-Jan-2415,000411-Feb-2412,000335-Mar-2416,0004428-Jun-2420,000551-Dec-24
16Contract B2-Jan-2212,000331-Feb-24
17
18
19Jan-24Feb-24Mar-24Apr-24May-24Jun-24Jul-24Aug-24Sep-24Oct-24Nov-24Dec-24Total
20Contract A0
21Contract B0
22
23Contract A should be:821,0001,3151,3331,3331,3481,6671108,188
24Contract B should be:1,000331,033
Hori
Cell Formulas
RangeFormula
H15,E15:E16,N15,K15H15=G15/365
O20:O21,O23:O24O20=SUM(C20:N20)
C23C23=E15*2
D23,G23D23=G15/12
E23E23=H15*4+K15*27
F23,I23F23=J15/12
H23H23=K15*27+N15*3
J23J23=N15*2
C24C24=D16/12
D24D24=E16*1
 
Upvote 0
See if the following formula works for your new data layout:
Excel Formula:
=LET(s,{1,4,7,10,13},x,$C15:$Q15,e,$O15,v,INDEX(x,s),y,INDEX(x,s+1),z,INDEX(x,s+2),a,C$19,b,EOMONTH(a,0),c,IFERROR(LOOKUP(a,v),e),d,LOOKUP(b,v),
IF(AND(a>=c,b>=d,c=d),LOOKUP(d,v,y)/12+(a=e)*LOOKUP(EDATE(e,-1),v,z),((d=e)+d-a)*LOOKUP(c,v,z)+(b-d+1)*LOOKUP(d,v,z)))
 
Upvote 0
hi Tetra, thanks for helping with this. where it refers to $C15:$Q15, should that be $C15:$N15?
 
Upvote 0
hi @Tetra201 I'm not sure why it's $C15:$Q15 but it works...! will I be able to amend the formula to account for more variations?

when amending dates I come across some problems which I can't figure out how to fix, e.g.
1. contract B start date change from 2-Jan-2022 to 2-Jan-2024 it produces N/A errors for Feb-24 to Dec-24
2. contrct start date 1-Jan-2024 and end 31-Dec-24 seems to produce wrong value for Dec-24

monthly value formula.xlsx
ABCDEFGHIJKLMNOP
13StartVariation 1Variation 2Variation 3
14ReferenceStartAnnualised valueDaily valueV1 startAnnualised valueDaily valueV2 startAnnualised valueDaily valueV3 startAnnualised valueDaily valueEnd date
15Contract A30-Jan-2415,000411-Feb-2412,000335-Mar-2416,0004428-Jun-2420,000551-Dec-24
16Contract B2-Jan-2412,000331-Feb-24
17Contract C1-Jan-2412,0003331-Dec-24
18
19Jan-24Feb-24Mar-24Apr-24May-24Jun-24Jul-24Aug-24Sep-24Oct-24Nov-24Dec-24Total
20Contract A821,0001,3151,3331,3331,3481,6671,6671,6671,6671,6675514,800
21Contract B986#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A
22Contract C1,0001,0001,0001,0001,0001,0001,0001,0001,0001,0001,0001,01912,019
23
24Contract A should be:821,0001,3151,3331,3331,3481,6671,6671,6671,6671,6675514,800manual calc
25Contract B should be:986331,019manual calc
26Contract C should be:1,0001,0001,0001,0001,0001,0001,0001,0001,0001,0001,0001,00012,000manual calc
27
28A - delta0000000000000should be nil
29B - delta0#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/Ashould be nil
30C - delta000000000001919should be nil
Hori
Cell Formulas
RangeFormula
H15,E15:E17,N15,K15H15=G15/365
C20:N22C20=LET(s,{1,4,7,10,13},x,$C15:$Q15,e,$O15,v,INDEX(x,s),y,INDEX(x,s+1),z,INDEX(x,s+2),a,C$19,b,EOMONTH(a,0),c,IFERROR(LOOKUP(a,v),e),d,LOOKUP(b,v), IF(AND(a>=c,b>=d,c=d),LOOKUP(d,v,y)/12+(a=e)*LOOKUP(EDATE(e,-1),v,z),((d=e)+d-a)*LOOKUP(c,v,z)+(b-d+1)*LOOKUP(d,v,z)))
O20:O22,O28:O30,O24:O26O20=SUM(C20:N20)
C24C24=E15*2
D24,G24D24=G15/12
E24E24=H15*4+K15*27
F24F24=J15/12
H24H24=K15*27+N15*3
I24:M24I24=$M$15/12
N24N24=N15*1
C25C25=30*E16
D25D25=E16*1
C26:N26C26=$D$17/12
C28:N30C28=C20-C24
 
Upvote 0
The following revamped formula seems to address the issues:
Excel Formula:
=LET(s,{1,4,7,10},cr,$C15:$N15,cx,INDEX(cr,s),cy,INDEX(cr,s+1),cz,INDEX(cr,s+2),cs,$C15,ce,$O15,
ms,MAX(cs,C$19),me,MIN(ce,EOMONTH(C$19,0)),xs,XLOOKUP(ms,cx,cx,,-1),xe,XLOOKUP(me,cx,cx,,-1),
IF(AND(DAY(ms)=1,EOMONTH(ms,0)=me,xs=xe),XLOOKUP(xs,cx,cy,,-1)/12,IF(ms>me,,(xe-ms)*XLOOKUP(xs,cx,cz,,-1)+(me-xe+1)*XLOOKUP(xe,cx,cz,,-1))))
 
Upvote 1
Solution

Forum statistics

Threads
1,223,881
Messages
6,175,161
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top