SumProduct on a variable length using a mask

Calgary_Neil

Board Regular
Joined
Apr 5, 2014
Messages
79
I have been using this formula {which is working fine}
Excel Formula:
SUMPRODUCT( N( MOD( COLUMN( $I37:AJ37)) -6, 7)= 0), $I37:AJ37) +F37
where the first part creates a mask for every 7 column, Middle part is numbers, text and blanks which only every 7th is needed, and the last part is a offset value. I extend this by inserting columns before Column AJ in batches of 7.

Now I what to do is sum every 7th column from $I to AJ-21 {with AJ increasing with inserted column counts}. I have tried OFFSET , it is dynamic I know, but it returns values which fail in COLUMNs.

Anyone have solution?
Thanks for reading
Neil T
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Here's one way you could do it (not sure if you want totals column by column, or just a grand total?):

IJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJ
18111111311111121111119111111
22111111611111121111117111111
34111111111111171111113111111
4
5
614101119
7
854
Sheet1
Cell Formulas
RangeFormula
I6:L6I6=SUMPRODUCT(INDEX($I1:$AJ3,,1+7*(COLUMNS($I6:I6)-1)))
I8I8=SUM(I1:AJ3*NOT(MOD(COLUMN(I1:AJ3)-COLUMN(I1:I3),7)))
Press CTRL+SHIFT+ENTER to enter array formulas.


I suggest you update your signature to let us know which version(s) of Excel you're using - the best solution may vary with version.
 
Upvote 0
Thanks. Need to play with it, but I don't think it does what I want.

Neil10C2_SE_4X_CE_V2.60.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASATAUAVAWAXAYAZBABBBCBDBEBFBGBHBIBJBKBLBMBNBOBPBQBRBSBTBUBVBWBXBYBZCACBCCCDCECFCGCHCICJCKCLCMCNCOCPCQCRCSCTCUCVCWCXCYCZDADBDCDDDEDFDGDHDIDJDKDLDMDNDODPDQDRDSDTDUDVDWDXDYDZEAEBECEDEEEFEGEHEIEJEKELEMENEOEPEQER
217Week 1Week 2Week 3Week 4Week 5Week 6Week 7Week 8Week 9Week 10Week 11Week 12Week 13Week 14Week 15Week 16Week 17Week 18Week 19Week 20
3170Parts in Stock25Parts in Stock32Parts in Stock38Parts in Stock54Parts in Stock68Parts in Stock65Parts in Stock74Parts in Stock84Parts in Stock86Parts in Stock81Parts in Stock97Parts in Stock91Parts in Stock96Parts in Stock97Parts in Stock101Parts in Stock124Parts in Stock117Parts in Stock122Parts in Stock124Parts in Stock124
4
51332532385468657484868197919697101124117122124124
Sheet1
Cell Formulas
RangeFormula
B3B3=SUMPRODUCT( N( MOD( COLUMN( $I3:ER3)-6, 7) =0), $I3:ER3) /10
B5B5=SUM(I5:DU5)/10
What I want to do is based on A2, get the value of $I$3 to 9+7*A2 row 3, masking the other cells except every 7th cell starting @ M (13th column). Row 5 shows this in a manual way. Other rows have numbers in different columns and may have numbers in more than 1 column in the set of seven, hence the masking. It's getting the variable length to work with the masking that I think I'm having problems with.
 
Upvote 0
Since you have Excel 365, I would consider using SEQUENCE to form the indexing array and use an idea like the one below. Here you can simply change the Number of weeks to extend the indexing array automatically. The few rows below your original ones show how the different components in the main formula work to build the indexing array {1,2,3,...}, how MOD is used to identify only the values of interest, and how SUM then adds those terms (only the yellow cells are needed, the others used for illustration purposes can be deleted). Just make sure the INDEX($I$3:$ZZ$3 part of the formula extends far enough to cover the entire range you want to add (it can be much larger than needed as I've shown here with $ZZ$3).
MrExcel_20220512B.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABAC
1
217Week 1Week 2Week 3
3170Parts in Stock25Parts in Stock32Parts in Stock38
4
5133253238
6123456789101112131415161718192021
7Sequence starts at1000025000000320000003800
8Number of weeks20170
9Sum/10170
Sheet2
Cell Formulas
RangeFormula
B3B3=SUMPRODUCT( N( MOD( COLUMN( $I3:ER3)-6, 7) =0), $I3:ER3) /10
B5B5=SUM(I5:DU5)/10
M5,AA5,T5M5=M3
I6:ER6I6=SEQUENCE(1,7*$B$8)
I7:ER7I7=INDEX(I3:ZZ3,,I6#*(MOD(I6#,7)=5))
I8I8=SUM(INDEX($I$3:$ZZ$3,,I6#*(MOD(I6#,7)=5)))/10
B9B9=SUM(INDEX($I$3:$ZZ$3,,SEQUENCE(1,7*$B$8)*(MOD(SEQUENCE(1,7*$B$8),7)=5)))/10
Dynamic array formulas.
 
Last edited:
Upvote 0
Quick look I don’t see A2 being a variable in adjusting the length. Will this work with INDIRECT (which is also dynamic) or is there a better way?
 
Upvote 0
Cell B8 in my example is effectively the same as cell A2 in your example. It establishes how many weeks are involved in the SUM. I wouldn't say that INDIRECT is dynamic...it is volatile, meaning that it needs to execute every time the sheet recalculates. This can lead to slow performance. In the orange version, I changed the cell reference for number of weeks to A2 and shortened the formula slightly by using a LET function to define the redundant indexing array term with a short name that is referenced elsewhere in the main formula. Give the orange cells a try and see if the desired results are produced.
MrExcel_20220512B.xlsx
ABCDEFGHIJKLMN
1
217Week 1
3170Parts in Stock25
4
513325
6
7Sequence starts at1
8Number of weeks17
9Sum/10133
10Sum/10133
Sheet2 (2)
Cell Formulas
RangeFormula
B3B3=SUMPRODUCT( N( MOD( COLUMN( $I3:ER3)-6, 7) =0), $I3:ER3) /10
B5B5=SUM(I5:DU5)/10
M5M5=M3
B9B9=SUM(INDEX($I$3:$ZZ$3,,SEQUENCE(1,7*$B$8)*(MOD(SEQUENCE(1,7*$B$8),7)=5)))/10
B10B10=LET(idx,SEQUENCE(1,7*$A$2),SUM(INDEX($I$3:$ZZ$3,,idx*(MOD(idx,7)=5)))/10)
 
Upvote 0
Solution
Thanks. That works, now I have to understand it. The only one new is SEQUENCE, but that is excel always 1 new method of Function to master.
 
Upvote 0
I'm happy to help. SEQUENCE is indeed dynamic. It creates an array tailored to your inputs: number of rows, columns, start number, and step size. In this case, it's easy to establish an array {1,2,3,...} to cover all of the cells in your range of interest. Then we do a MOD 7 on the array, and since the MOD 7 of every value in your sum range is 5, we can use INDEX in conjunction with the MOD 7 condition to return only the values of interest from your sum range. Study the illustrative example in my Post #4 to see this (in I6:I7).
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,636
Latest member
laura12345

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