Calculate PRODUCT of a sub-range in a Google Sheets range

落爺英雄遲暮 提交于 2020-05-17 07:53:05

问题


I have a range with Type for columns and Level for rows. I need to find the PRODUCT of a sub-range which is from Level 1 to the given Level of given Type.

So far I tried to find the position of the starting and ending cells of sub-range by using:

=CELL("address",INDEX(A1:N21,2,MATCH(R4,A1:N1,0)))

=CELL("address",index(A1:N21,R3+1,match(R4,A1:N1,0)))

Then I think about using CONCATENATE to give the range address but it returns 0.

Example sheet: https://docs.google.com/spreadsheets/d/1byIjDzHZE6s5N1PcN9yvSeC51bm9NVVC1tc1gjQQLHA/edit#gid=0


回答1:


You are right, you don't need such a long formula. Index returns a cell reference, so you can do something in the form of index(...startrow,startcol):index(...endrow,endcol) like this:

=PRODUCT(INDEX(A1:N21,2,MATCH(R4,A1:N1,0)):INDEX(A1:N21,R3+1,MATCH(R4,A1:N1,0)))

Even shorter is offset:

=PRODUCT(offset(A1,1,MATCH(R4,A1:N1,0)-1,R3,1))



回答2:


I found one solution by using the reference to the range:

=PRODUCT(INDIRECT(CELL("address",INDEX(A1:N21,2,MATCH(R4,A1:N1,0)))&":"&CELL("address",INDEX(A1:N21,R3+1,MATCH(R4,A1:N1,0)))))

However, it is quite long. I would like to have a better solution in the case.



来源:https://stackoverflow.com/questions/61208151/calculate-product-of-a-sub-range-in-a-google-sheets-range

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!