Sumif Provided Other Rows = x

andybason

Board Regular
Joined
Jan 7, 2012
Messages
217
Office Version
  1. 2016
Hi all,

I have a table (extract below) and I am using the following formula to sum the values in F where the Q3 criteria is met:

Code:
=SUMIF(E2:E77,$Q$3,F2:F77)

I would like to adapt it to only sum modelIDs that have a 1, 2, 3, 4 or 5 in range L2:L77.

Is this possible?

Thanks


Book1
ABCDEFGHIJKL
1modelIdSkustockVar1Var2C1C2C3C4C5orderRank
21034825114592572538020000001
31034825124592572538020000002
41034825134592572538024000003
51034825144592572538021000004
61034825162889922538021000105
71034825172889922538020000006
81034825182889922538020000007
91034825182889922538021001007
101034825192889922538020000009
11103482511028899225380240000010
12103482511128899225380200000011
13103482511228899225380210000012
14103482511345925725380210000013
15103482511745925725380210000014
1610348251191926425380240000015
1710348251201926425380240000016
1810348251211926425380200000117
1910348251221926425380210000018
2010348251241926425380210000019
21103482512528899225380210000020
22103482513028899225380210000021
2310348251311926425380210000022
2410348251351926425380210000023
25103482513731115825380210000024
26103482514031115825380210000025
27103482514231115825380210000026
281034825143891725380200000127
2910235951155143381800000001
3010235951165143381800000002
3110235951175143381800000003
3210235951185143381800000004
33102359512055585381800000005
34102359512155585381800000016
35102360521730825181801000001
36102360521977422381800000002
37102360522077422381802000003
38102360522177422381800000004
39102360522277422381800000005
40102360522377422381800000006
41102360522477422381800000017
42102361122744654881803000001
43102361123044654881800000002
441023611234594181800000013
4510236192391061781800000001
4610236192401061781801000002
4710236192421061781801000003
48102361924332662581801000004
49102361924532662581800000005
50102361924632662581806000006
51102361924732662581800000007
52102361924832662581800000008
5310236192501061781801000009
54102361925210617818000000010
55102361925310617818010000011
561023619260326625818010000012
5710236192608076818030003012
5810236192618076818040000014
5910236192628076818000000015
6010236192638076818010000016
6110236192658076818040000017
6210236192668076818060000018
631023619268326625818010000019
641023619270326625818010000020
651023619272326625818010000021
6610236192734864818010000022
6710236192784864818060000023
681023619281308798818000000024
691023619282308798818010000025
701023619284308798818010000026
7110236192854864818060000027
7210236192864864818000000028
7310236192874864818020000029
7410236192884864818060000030
7510236192894864818000000131
76102362923439866681804000001
77102362923539866681800000002
Sheet3
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Andy, Not sure if you want 1-5 total or just limited to ID in Q3.
Either way then use SUMIFS

Book1
MNOPQ
2All ID's19
3Limited To Q36253802
Sheet5
Cell Formulas
RangeFormula
N2N2=SUMIFS(F2:F77,L2:L77,">0",L2:L77,"<6")
N3N3=SUMIFS(F2:F77,E2:E77,$Q$3,L2:L77,">0",L2:L77,"<6")


Hope that helps.
 
Upvote 0
Hi snakehips,

Sorry, I phrased my request badly...

I would like to sum modelIDs that have a 1, 2, 3, 4 and 5 in range L2:L77.

So, eg, if a modelid had only a 1, 2, 3 and 4 that modelid should not be included in the sum.

Also, it should be limited to Q3. Is this possible?

Thanks
 
Upvote 0
It could be with an "auxiliary" column to identify which modelid have 1,2,3,4,5 and then in another cell the sum.

Dante Amor
ABCDEFGHIJKLMNQ
1modelIdSkustockVar1Var2C1C2C3C4C5orderRankAuxSum
210348251145925725380200000010 9.00
3103482512459257253802000000208180
410348251345925725380240000034
510348251445925725380210000041
610348251628899225380210001051
710348251728899225380200000060
810348251828899225380200000070
9102359511551433818000000010
10102359511651433818000000020
11102359511751433818000000030
12102359511851433818000000040
131023611227446548818030000010
141023611230446548818000000020
1510236112345941818000000130
16102361923910617818000000010
17102361924010617818010000021
18102361924210617818010000031
191023619243326625818010000041
201023619245326625818000000050
211023619246326625818060000066
221023629234398666818040000010
231023629235398666818000000020
Sheet3
Cell Formulas
RangeFormula
N2N2=SUMIF(E2:E23,Q3,M2:M23)
M2:M23M2=IF(SUM(COUNTIFS($A$2:$A$23,A2,$L$2:$L$23,{1,2,3,4,5}))=5,F2,0)
 
Last edited:
Upvote 0
How's about...
Book1
NOPQ
36253802
Sheet5
Cell Formulas
RangeFormula
N3N3=IF(COUNTIFS(L2:L77,5,E2:E77,$Q$3)>0,(SUMIFS(F2:F77,E2:E77,$Q$3,L2:L77,">0",L2:L77,"<6")),"")
 
Upvote 0
Hi snakehips,

I have just tried this formula on a larger data set and it still seems to be summing modelIds that have only a 1, 2, 3, or 4. Ideally I would like to avoid a helper column if possible.

Thanks

How's about...
Book1
NOPQ
36253802
Sheet5
Cell Formulas
RangeFormula
N3N3=IF(COUNTIFS(L2:L77,5,E2:E77,$Q$3)>0,(SUMIFS(F2:F77,E2:E77,$Q$3,L2:L77,">0",L2:L77,"<6")),"")
 
Upvote 0
Hi Andy,

Will my current understanding, I see nothing wrong with this. ???????
Counting only if 1,2,3,4,AND 5
Book1
ABCDEFGHIJKLMNOPQ
1modelIdSkustockVar1Var2C1C2C3C4C5orderRank
21034825114592572538020000001
31034825124592572538024000002237253802
41034825134592572538020000003
51034825144592572538021000004
610348251628899225380299000105
710348251728899225380222000005
81034825182889922538020000007
91034825182889922538021001007
101034825192889922538020000009
11103482511028899225380240000010
121034825111288992253802111000005
13103482511228899225380210000012
Sheet5
Cell Formulas
RangeFormula
N3N3=IF(COUNTIFS(L2:L77,5,E2:E77,$Q$3)>0,(SUMIFS(F2:F77,E2:E77,$Q$3,L2:L77,">0",L2:L77,"<6")),"")
L2:L5, L13, L8:L11L2=COUNTIFS($A$2:$A$77,A2,$E$2:$E$77,E2,$C$2:$C$77,"<"&C2)+1


Not counting if NOT 5 ??
Book1
ABCDEFGHIJKLMNOPQ
1modelIdSkustockVar1Var2C1C2C3C4C5orderRank
21034825114592572538020000001
31034825124592572538024000002 253802
41034825134592572538020000003
51034825144592572538021000004
610348251628899225380299000107
710348251728899225380222000007
81034825182889922538020000007
91034825182889922538021001007
101034825192889922538020000009
11103482511028899225380240000010
1210348251112889922538021110000010
Sheet5
 
Upvote 0
Hi Snakehips,

In the extract below the formula sums the values for ModelID 1034829 but there is only a 1 and a 2 for that ModelID in column L. It should return 6 summing the yellow highlighted cells but also includes the orange highlighted cells.

Thanks

Book1
ABCDEFGHIJKLMNOPQ
1ModelIdSkustockVar1Var2C1C2C3C4C5orderRank
21031665240315594308967000000110
310316652413155943089671000002308967
410316652482305583089670000003
510316652513155943089670000004
610316652523155943089672000005
710316652533155943089674000006
810316652543155943089671000007
910316652552305583089672000008
1010316652562305583089670000009
11103166525723055830896710000010
12103166525923055830896710000011
13103166526431559430896720000012
14103166526531559430896720000013
15103166526631559430896710000014
16103166526723055930896720000015
17103166526823055930896700000016
18103166526923055930896700000017
19103166527023055930896740000018
20103166527123055930896700000019
21103166527223055930896710000020
22103166527345007530896700000021
23103166527445007530896720000022
24103166527545007530896710000023
25103166527645007530896710010024
26103166527745007530896710000025
27103166528123055930896710000026
28103166528323055930896710000027
29103166528545007530896700000128
3010348272102318203089671000001
31103482721036253833089670000002
32103482721046253833089670000003
33103482721056253833089671000004
3410348272109318203089671000005
3510348272112318203089674000006
3610348272113318203089672000007
3710348272114318203089676000008
38103482721176253833089670000009
391034827211862538330896700000110
4010348292856253833089670000001
4110348292866253833089674000012
4210683001394730043089674000001
Sheet2
Cell Formulas
RangeFormula
P2P2=IF(COUNTIFS(L2:L41,5,E2:E41,$Q$3)>0,(SUMIFS(F2:F41,E2:E41,$Q$3,L2:L41,">0",L2:L41,"<6")),"")
 
Upvote 0

Forum statistics

Threads
1,215,419
Messages
6,124,796
Members
449,189
Latest member
kristinh

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