Home » excel » arrays – Conditional SUM using multiple tables in EXCEL

arrays – Conditional SUM using multiple tables in EXCEL

Questions:

I have a table that I’m trying to populate based on the values of two reference tables.

I have various different projects ‘Type 1’, ‘Type 2’ etc. that each run for 4 months and cost different amounts depending on when in their life cycle they are. These costings are shown in `Ref Table 1`.

Ref Table 1

``````Month    |  a  |  b  |  c  |  d
---------------------------------
Type 1   |  1  |  2  |  3  |  4
Type 2   |  10 | 20  |  30 |  40
Type 3   | 100 | 200 | 300 | 400
``````

`Ref Table 2` shows my schedule of projects for the next 3 months. With 2 new ones starting in Jan, one being a `Type 1` and the other being a `Type 2`. In Feb, I’ll have 4 projects, the first two entering their second month and two new ones start, but this time a Type 1 and a Type 3.

Ref table 2

``````Date    | Jan | Feb | Mar
--------------------------
Type 1  |  a  |  b  |  c
Type 1  |     |  a  |  b
Type 2  |  a  |  b  |  c
Type 2  |     |     |  a
Type 3  |     |  a  |  b
``````

I’d like to create a table which calculates the total costs spent per project type each month. Example results are shown below in `Results` table.

Results

``````Date    | Jan | Feb | Mar
-------------------------------
Type 1  |  1  |  3  |  5
Type 2  |  10 |  20 |  40
Type 3  |  0  | 100 | 200
``````

I tried doing it with an array formula:

``````Res!b2 = {sum(if((Res!A2 = Ref2!A2:A6) * (Res!A2 = Ref1!A2:A4) * (Ref2!B2:D6 = Ref1!B1:D1), Ref!B2:E4))}
``````

However it doesn’t work and I believe that it’s because of the third condition trying to compare a vector with another vector rather than a single value.

Does anyone have any idea how I can do this? Happy to use arrays, index, match, vector, lookups but NOT VBA.

Thanks

`=SUM(SUMIF(Ref1!\$B\$1:\$E\$1,IF(Ref2!\$A\$2:\$A\$6=Res!\$A2,Ref2!B\$2:B\$6),INDEX(Ref1!\$B\$2:\$E\$4,MATCH(Res!\$A2,Ref1!\$A\$2:\$A\$4,0),0)))`
confirm with `CTRL+SHIFT+ENTER` and copy down and across
If the months might be in different orders then you can add something to check that too – I assumed that the types in results table row labels might be in a different order to Ref table 1, but if they are always in the same order too (as per your example) then the `INDEX/MATCH` part at the end can be simplified to a single range