简体   繁体   中英

Calculate the Sum of same rows from different columns using Excel formula

My actual data belong to Column G to N, where I've Name and quarter columns. Column A contains 2 quarters and I want to calculate VAL1 and VAL2.

在此处输入图像描述

Logic to create VAL1:

  • for 2021Q2, identify all the non-zero Names from Column M (2021Q2) then SUM values of (M,L,K) for the same Names.
  • for 2021Q3, identify all the non-zero Names from Column N (2021Q3) then UM values of (N,M,L) for the same Names.

Logic to create VAL2:

  • for 2021Q2, identify all the non-zero Names from Column M (2021Q2) then SUM values of (J,I,H) for the same Names.
  • for 2021Q3, identify all the non-zero Names from Column N (2021Q3) then UM values of (K,J,I) for the same Names.

I've tried few approaches, like identify the location using ADDRESS(MATCH), getting ROW numbers, but didn't work properly. Can anyone please help with a formula to get the desired values?

1] In B2 , formula copied down:

=SUMPRODUCT((OFFSET($G$2,0,MATCH($A2,$H$1:$N$1,0),7)<>0)*OFFSET($G$2,0,MATCH($A2,$H$1:$N$1,0),7,-3))

2] In C2 , formula copied down:

=SUMPRODUCT((OFFSET($G$2,0,MATCH($A2,$H$1:$N$1,0),7)<>0)*OFFSET($G$2,0,MATCH($A2,$H$1:$N$1,0)-3,7,-3))

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM