Combining SUMPRODUCT and INDEX functions

Ioweyouone

New Member
Joined
Aug 14, 2009
Messages
38
Office Version
  1. 365
Platform
  1. Windows
To all: I'm struggling with this SUMPRODUCT function. Cell B3 needs to add up all the shapes lengths, depending on their quantity. When I remove the blanks and zeros, my formula returns 80, which is incorrect. It should be 61. When finished, this table will have 200 columns and 700 rows of data. Hoping for a simple formula. Thanks.


1726501521613.jpeg
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Try:

Book1
ABCDEFG
1
2
3TOTAL LENGTH OF ALL SHAPES61
4
5SHAPESTotal QTY.Length if 1 UnitLength if 2 UnitsLength if 3 UnitsLength if 4 Units
6Square110203040
7Right Triangle210102020
8Parallelogram310182638
9Triangle210152025
10Circle020304050
11Line8
12
Sheet8
Cell Formulas
RangeFormula
B3B3=SUM(IFERROR(INDEX(C6:F11,SEQUENCE(6),1/(1/B6:B11)),0))
 
Upvote 0
Eric W,
Thanks for your response. I tried your formula in my sheet, and it seems to work fine (although I don't understand how it works!) Is there a way to change SEQUENCE(6) and make it dynamic to change if I add more rows?
 
Upvote 0
Consider:

Book1
ABCDEFG
1
2
3TOTAL LENGTH OF ALL SHAPES7070
4
5SHAPESTotal QTY.Length if 1 UnitLength if 2 UnitsLength if 3 UnitsLength if 4 Units
6Square110203040
7Right Triangle210102020
8Parallelogram310182638
9Triangle210152025
10Circle020304050
11Line8
12Rhombus31234
13Octagon25678
14
Sheet8
Cell Formulas
RangeFormula
B3B3=SUM(IFERROR(INDEX(C6:Z1005,SEQUENCE(1000),1/(1/B6:B1005)),0))
C3C3=LET(rng_1,A6:A1000,rws,COUNTA(rng_1),qty,1/(1/OFFSET(B6,0,0,rws)),rng_2,OFFSET(C6:F6,0,0,rws),SUM(IFERROR(INDEX(rng_2,SEQUENCE(rws),qty),0)))


The B3 is the same formula, just with the ranges enlarged and the SEQUENCE value increased. The formula is already designed to ignore empty cells, so as long as there's nothing below or to the right, it'll work just fine.

The C3 formula is designed to expand vertically based on the number of values in A6:A1000, so row 1000 is the top. But if you have something in that range not related to your table, that could cause problems. So you might just want to stick with the previous version anyway. It doesn't expand to the right, but that could be done too if you want, but it'll make the formula longer.

Which raises a point, all formulas use the B column to say how far to the right to grab the value, so it will work as long as the values in C5:F5 just increment by 1. If you do something like 1,2,3,4,5,10,20, etc., then we'd need to adapt the formula.

The formula is pretty basic, it uses the SEQUENCE to pick the row, and the B value to pick the column for that row. Then the INDEX looks up the values for each row and SUMs them. The 1/(1/ structure is to turn a 0 into a #DIV/0! error, otherwise INDEX interprets a 0 as a 1.

Hope this helps!
 
Last edited:
Upvote 0
Solution

Forum statistics

Threads
1,221,527
Messages
6,160,342
Members
451,638
Latest member
MyFlower

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