How to write sum if formula if criteria is a variable parameter?

Iris14

New Member
Joined
Feb 16, 2014
Messages
11
[TABLE="width: 354"]
<colgroup><col><col span="3"></colgroup><tbody></tbody>[/TABLE]
I have a Table 1 which contained the sub account number and the related amount. The sub account numbers are then grouped to a master account number which is presented in Table 2. Table 2 is like a directory to guide what sub account numbers need to be added together.

[TABLE="width: 226"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD]Table 1[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]Sub Account number[/TD]
[TD]Amount[/TD]
[/TR]
[TR]
[TD]SDFG[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]D[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD]FG[/TD]
[TD="align: right"]3[/TD]
[/TR]
[TR]
[TD]D[/TD]
[TD="align: right"]6[/TD]
[/TR]
[TR]
[TD]GH[/TD]
[TD="align: right"]8[/TD]
[/TR]
[TR]
[TD]T[/TD]
[TD="align: right"]854[/TD]
[/TR]
[TR]
[TD]RH[/TD]
[TD="align: right"]565[/TD]
[/TR]
[TR]
[TD]H[/TD]
[TD="align: right"]45[/TD]
[/TR]
[TR]
[TD]GH[/TD]
[TD="align: right"]546[/TD]
[/TR]
[TR]
[TD]GH[/TD]
[TD="align: right"]54[/TD]
[/TR]
[TR]
[TD]J[/TD]
[TD="align: right"]5[/TD]
[/TR]
[TR]
[TD]GH[/TD]
[TD="align: right"]2[/TD]
[/TR]
</tbody>[/TABLE]

[TABLE="width: 354"]
<colgroup><col><col span="3"></colgroup><tbody>[TR]
[TD]Table 2[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]Master account 1[/TD]
[TD]GH[/TD]
[TD]J[/TD]
[TD]T[/TD]
[/TR]
</tbody>[/TABLE]


I would like to do a sum if formula to sum the amount in table 1 if column A of Table 1 (the sub account number) matches any of the account number in row 1 of Table 2.

The number of sub account number in the Master account is variable.

I have tried to build array formula like {=SUM(IF(A:A={"GH","J","T"},B:B,0))}
But then the account number would need to be keyed in manually and there are a lot of sub account numbers that needed to be built into the formula.

I would like to ask if there is anyway to build formula, e.g. match, address, lookup, index and etc to do the work (adding the amount in table 1 of any sub account numbers that belong to the same master account).

Thank you very much for any help!!!
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
try something like this

=SUM(IF(ISERROR(MATCH(A:A,C1:F1,0))=FALSE,B:B,0))
C1:F1 consist of those {"GH","J","T"} letters
 
Upvote 0
couple of other options



Excel 2007
ABCDEF
1Sub Account numberAmountGHJT
2SDFG1
3D2
4FG3
5D6
6GH8
7T854
8RH565
9H45
10GH546
11GH54
12J5
13GH2
141469
151469
Sheet1
Cell Formulas
RangeFormula
D14=SUMIF(A2:A13,D1,B2:B13)+SUMIF(A2:A13,E1,B2:B13)+SUMIF(A2:A13,F1,B2:B13)
D15=SUMPRODUCT(--(A2:A13=D1)+(A2:A13=E1)+(A2:A13=F1),B2:B13)
 
Upvote 0
Assuming your values are in Row 1 of Table2:

=SUMPRODUCT((A2:A12=Table2!1:1)*B2:B12)
 
Upvote 0
Thanks a lot vlady for your prompt reply !!! It works !!! Thanks a lot for your great help !!! It is very much appreciated.
 
Upvote 0
Thank you all for the prompt reply !!! It is a great forum. I definitely find the right spot !:cool:
 
Upvote 0

Forum statistics

Threads
1,223,240
Messages
6,170,951
Members
452,368
Latest member
jayp2104

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