Dynamic formula to calculate progressive difference between values from the same period of two years

vladimiratanasiu

Active Member
Joined
Dec 17, 2010
Messages
347
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hello!

I have a large table with the consumption of electricity in 50 points over many years. I need a dynamic solution to calculate automatically the annual difference (e.g. 5 Kwh, -155 Kwh) between a period of one year (e.g. January-June 2021; January-August 2022) with the same period of the previous year (January-June 2020; January-August 2021). It should take into consideration the last numerical value added progressively, excluding only the non-value cells. How could I do it?

Thank you in advance!

Book1.xlsx
BCDEFGHI
2PeriodElectricity consumption (Kwh)PeriodElectricity consumption (Kwh)PeriodElectricity consumption (Kwh)PeriodElectricity consumption (Kwh)
3Jan-20180Jan-21185Jan-21185Jan-22160
4Feb-20170Feb-21175Feb-21175Feb-22155
5Mar-20120Mar-21130Mar-21130Mar-22127
6Apr-20100Apr-2190Apr-2190Apr-2292
7May-2080May-2180May-2180May-2261
8Jun-2060Jun-2155Jun-2155Jun-220
9Jul-2050Jul-2134Jul-2134Jul-220
10Aug-2040Aug-2142Aug-2142Aug-2241
11Sep-2060Sep-2155Sep-2155Sep-22
12Oct-2080Oct-2176Oct-2176Oct-22
13Nov-20100Nov-21109Nov-21109Nov-22
14Dec-20140Dec-21134Dec-21134Dec-22
15Annual difference (+/-)5Annual difference (+/-)-155
Sheet1
Cell Formulas
RangeFormula
E15E15=SUM(E3:E8)-SUM(C3:C8)
I15I15=SUM(I3:I10)-SUM(G3:G10)
 
Last edited:

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
from how i took your request, i believe this is could work for what you're looking for. please let me know if so, or what changes may be needed.
---------------------------
Book1
ABCDEFGHI
1
2PeriodElectricity consumption (Kwh)PeriodElectricity consumption (Kwh)PeriodElectricity consumption (Kwh)PeriodElectricity consumption (Kwh)
31/1/20201801/1/20211851/1/20211851/1/2022160
42/1/20201702/1/20211752/1/20211752/1/2022155
53/1/20201203/1/20211303/1/20211303/1/2022127
64/1/20201004/1/2021904/1/2021904/1/202292
75/1/2020805/1/2021805/1/2021805/1/202261
86/1/2020606/1/2021556/1/2021556/1/20220
97/1/2020507/1/2021347/1/2021347/1/20220
108/1/2020408/1/2021428/1/2021428/1/202241
119/1/2020609/1/2021559/1/2021559/1/2022
1210/1/20208010/1/20217610/1/20217610/1/2022
1311/1/202010011/1/202110911/1/202110911/1/2022
1412/1/202014012/1/202113412/1/202113412/1/2022
15Annual difference (+/-)5Annual difference (+/-)-155
Sheet1
Cell Formulas
RangeFormula
E15,I15E15=IF(YEAR(D14)=YEAR(TODAY()),SUM(OFFSET(E3,0,0,COUNTA(INDIRECT(ADDRESS(3,MATCH(160,3:3,0))&":"&ADDRESS(3+11,MATCH(160,3:3,0))))))-SUM(OFFSET(C3,0,0,COUNTA(INDIRECT(ADDRESS(3,MATCH(160,3:3,0))&":"&ADDRESS(3+11,MATCH(160,3:3,0)))))),SUM(OFFSET(E3,0,0,COUNTIF(INDIRECT(ADDRESS(3,MATCH(160,3:3,0))&":"&ADDRESS(3+11,MATCH(160,3:3,0))),">0")))-SUM(OFFSET(C3,0,0,COUNTIF(INDIRECT(ADDRESS(3,MATCH(160,3:3,0))&":"&ADDRESS(3+11,MATCH(160,3:3,0))),">0"))))
 
Upvote 0
from how i took your request, i believe this is could work for what you're looking for. please let me know if so, or what changes may be needed.
---------------------------
Book1
ABCDEFGHI
1
2PeriodElectricity consumption (Kwh)PeriodElectricity consumption (Kwh)PeriodElectricity consumption (Kwh)PeriodElectricity consumption (Kwh)
31/1/20201801/1/20211851/1/20211851/1/2022160
42/1/20201702/1/20211752/1/20211752/1/2022155
53/1/20201203/1/20211303/1/20211303/1/2022127
64/1/20201004/1/2021904/1/2021904/1/202292
75/1/2020805/1/2021805/1/2021805/1/202261
86/1/2020606/1/2021556/1/2021556/1/20220
97/1/2020507/1/2021347/1/2021347/1/20220
108/1/2020408/1/2021428/1/2021428/1/202241
119/1/2020609/1/2021559/1/2021559/1/2022
1210/1/20208010/1/20217610/1/20217610/1/2022
1311/1/202010011/1/202110911/1/202110911/1/2022
1412/1/202014012/1/202113412/1/202113412/1/2022
15Annual difference (+/-)5Annual difference (+/-)-155
Sheet1
Cell Formulas
RangeFormula
E15,I15E15=IF(YEAR(D14)=YEAR(TODAY()),SUM(OFFSET(E3,0,0,COUNTA(INDIRECT(ADDRESS(3,MATCH(160,3:3,0))&":"&ADDRESS(3+11,MATCH(160,3:3,0))))))-SUM(OFFSET(C3,0,0,COUNTA(INDIRECT(ADDRESS(3,MATCH(160,3:3,0))&":"&ADDRESS(3+11,MATCH(160,3:3,0)))))),SUM(OFFSET(E3,0,0,COUNTIF(INDIRECT(ADDRESS(3,MATCH(160,3:3,0))&":"&ADDRESS(3+11,MATCH(160,3:3,0))),">0")))-SUM(OFFSET(C3,0,0,COUNTIF(INDIRECT(ADDRESS(3,MATCH(160,3:3,0))&":"&ADDRESS(3+11,MATCH(160,3:3,0))),">0"))))
Thank you for the quick answer! I noticed your formula uses many times the value 160, referring to the electricity consumption from January 2022. Unfortunately, it works properly using only that value, otherwise it generates errors / false results as cells colored in yellow from my last attached table. Anyway, considering the formula could be ok and taking into account the numerical data are extended continuously, I should change manually that value many times. Could you make all necessary changes, so that the existing errors are removed and avoid manual changes when adding some new years? Thank you!
Book3
BCDEFGHI
2PeriodElectricity consumption (Kwh)PeriodElectricity consumption (Kwh)PeriodElectricity consumption (Kwh)PeriodElectricity consumption (Kwh)
3Jan-20180Jan-21185Jan-21185Jan-22170
4Feb-20170Feb-21175Feb-21175Feb-22155
5Mar-20120Mar-21130Mar-21130Mar-22127
6Apr-20100Apr-2190Apr-2190Apr-2292
7May-2080May-2180May-2180May-2261
8Jun-2060Jun-2155Jun-2155Jun-220
9Jul-2050Jul-2134Jul-2134Jul-220
10Aug-2040Aug-2142Aug-2142Aug-2241
11Sep-2060Sep-2155Sep-2155Sep-22
12Oct-2080Oct-2176Oct-2176Oct-22
13Nov-20100Nov-21109Nov-21109Nov-22
14Dec-20140Dec-21134Dec-21134Dec-22
15Annual difference (+/-)#N/AAnnual difference (+/-)-15
Sheet1
Cell Formulas
RangeFormula
E15,I15E15=IF(YEAR(D14)=YEAR(TODAY()),SUM(OFFSET(E3,0,0,COUNTA(INDIRECT(ADDRESS(3,MATCH(160,3:3,0))&":"&ADDRESS(3+11,MATCH(160,3:3,0))))))-SUM(OFFSET(C3,0,0,COUNTA(INDIRECT(ADDRESS(3,MATCH(160,3:3,0))&":"&ADDRESS(3+11,MATCH(160,3:3,0)))))),SUM(OFFSET(E3,0,0,COUNTIF(INDIRECT(ADDRESS(3,MATCH(160,3:3,0))&":"&ADDRESS(3+11,MATCH(160,3:3,0))),">0")))-SUM(OFFSET(C3,0,0,COUNTIF(INDIRECT(ADDRESS(3,MATCH(160,3:3,0))&":"&ADDRESS(3+11,MATCH(160,3:3,0))),">0"))))
 
Last edited:
Upvote 0
oops, i had that while working on it, but thought i had changed it. give me a min...
 
Upvote 0
try this:
Dynamic formula to calculate progressive difference between values from the same period of two years.xlsx
ABCDEFGHI
1
2PeriodElectricity consumption (Kwh)PeriodElectricity consumption (Kwh)PeriodElectricity consumption (Kwh)PeriodElectricity consumption (Kwh)
31/1/20201801/1/20211851/1/20211851/1/2022160
42/1/20201702/1/20211752/1/20211752/1/2022155
53/1/20201203/1/20211303/1/20211303/1/2022127
64/1/20201004/1/2021904/1/2021904/1/202292
75/1/2020805/1/2021805/1/2021805/1/202261
86/1/2020606/1/2021556/1/2021556/1/20220
97/1/2020507/1/2021347/1/2021347/1/20220
108/1/2020408/1/2021428/1/2021428/1/202241
119/1/2020609/1/2021559/1/2021559/1/2022
1210/1/20208010/1/20217610/1/20217610/1/2022
1311/1/202010011/1/202110911/1/202110911/1/2022
1412/1/202014012/1/202113412/1/202113412/1/2022
15Annual difference (+/-)5Annual difference (+/-)-155
Sheet1
Cell Formulas
RangeFormula
E15,I15E15=IF(YEAR(D14)=YEAR(TODAY()),SUM(OFFSET(E3,0,0,COUNTA(INDIRECT(ADDRESS(3,MATCH((LOOKUP(2,1/(3:3<>""),3:3)),3:3,0))&":"&ADDRESS(3+11,MATCH((LOOKUP(2,1/(3:3<>""),3:3)),3:3,0))))))-SUM(OFFSET(C3,0,0,COUNTA(INDIRECT(ADDRESS(3,MATCH((LOOKUP(2,1/(3:3<>""),3:3)),3:3,0))&":"&ADDRESS(3+11,MATCH((LOOKUP(2,1/(3:3<>""),3:3)),3:3,0)))))),SUM(OFFSET(E3,0,0,COUNTIF(INDIRECT(ADDRESS(3,MATCH((LOOKUP(2,1/(3:3<>""),3:3)),3:3,0))&":"&ADDRESS(3+11,MATCH((LOOKUP(2,1/(3:3<>""),3:3)),3:3,0))),">0")))-SUM(OFFSET(C3,0,0,COUNTIF(INDIRECT(ADDRESS(3,MATCH((LOOKUP(2,1/(3:3<>""),3:3)),3:3,0))&":"&ADDRESS(3+11,MATCH((LOOKUP(2,1/(3:3<>""),3:3)),3:3,0))),">0"))))
 
Upvote 0
Try this:

E15
Excel Formula:
=SUM(E3:E14)-SUM(C3:INDEX(C3:C14,COUNT(E3:E14)))

Copy to I15

In E15, this will calculate the difference until December 2021, since all months are already populated.
 
Upvote 0
Solution
Try this:

E15
Excel Formula:
=SUM(E3:E14)-SUM(C3:INDEX(C3:C14,COUNT(E3:E14)))

Copy to I15

In E15, this will calculate the difference until December 2021, since all months are already populated.
I have a similar issue (Divide the sum of values from the same periods of two consecutive years), but it approaches the proportion between the total values of two consecutive years. The tables are structured vertically, including within the columns also blank and numerical value cells . Could you see this topic and, if possible, find a proper formula to solve the problem? Thank you!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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