2
      A              B       C
1 Report Line   Data Type   Value  
2     1             a           10
3     1             b           20
4     1             c           30
5     2             a           40
6     2             b           50
7     2             c           60
8     3             a           70
9     3             b           80
10    3             c           90


     E           F
1 Report    Report Line
2      1          1
3      1          3
4      2          2
5      2          3

Hi,

in the above example, the first table shows report lines of which each can belong to one or more reports. The second table shows which report line belongs to which reports.

How do I summarize all rows in column C where data type is "a" for the lines that belong to report 2 in the table given in E:F? This should be 40+70=110.

I would like to do it without referencing any criteria ranges outside these two tables, one formula in one cell. Tried searching everything I could think of in match, index, sumifs, sumproduct...

Many thanks.

2
  • 1
    Can you index your second table to your first? i.e. add a column that says 'report', but for each record? Then it would be easy. Commented Jan 14, 2015 at 12:20
  • I am trying to avoid this approach. Commented Jan 14, 2015 at 16:29

1 Answer 1

1

you can use following array formula (entered by CTRL+SHIFT+ENTER):

=SUMPRODUCT(
    C2:C10,
    --(B2:B10="a"),
    --(ISNUMBER(MATCH(A2:A10,IF(E2:E5=2,F2:F5),0))))

Explanation (see also Excel vocabulary to find solutions faster):

  • IF(E2:E5=2,F2:F5) inside an array formula will check each cell from E2 to E5 and if it is equal to 2, it will append corresponding value from F-column, if not it will append FALSE to an output array
  • MATCH(A2:A10, inner_array, 0) is taking the inner_array as a normal argument, but because 1st argument is supposed to be only 1 value, inside an array formula it will check each cell from A2 to A10 for an exact match agains the provided inner_array, if a match is found it appends the position inside the inner_array, if not it appends #N/A! to an output array
  • ISNUMBER(array) when used in an array formula will check each element in provided array, it appends TRUE or FALSE to an output array
  • --(boolean_array) will convert each item in the array from boolean value to 0 or 1
  • SUMPRODUCT(range, array, array) will multiply the numbers at each corresponding position in provided ranges or arrays, then it will sum up all the results
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, this is impressive, I hope I will one day understand this formula. Also thanks for the vocabulary post, very useful.
@gorkas I added an explanation, hope it helps and please don't forget to accept the answer if it solved your problem :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.