Sum first n cells

raikks

Board Regular
Joined
Feb 23, 2020
Messages
53
Office Version
  1. 2019
Platform
  1. Windows
Hi - I need a formula that sums the first 3 cells of component1 that contains ``yes'' (result should be 88)
Also - I need to sum the first 3 cells of component1 & component2 that contains ``yes'' (result should be 121)
Thanks in advance.
 

Attachments

  • Untitled.png
    Untitled.png
    4.8 KB · Views: 18
OK, here you go:
=SUMIFS(C2:INDEX(C:C,SMALL(IF((A:A="yes")+(B:B="yes")=2,1,1000)*ROW(A:A),3)), A2:INDEX(A:A,SMALL(IF((A:A="yes")+(B:B="yes")=2,1,1000)*ROW(A:A),3)),"Yes", B2:INDEX(B:B,SMALL(IF((A:A="yes")+(B:B="yes")=2,1,1000)*ROW(A:A),3)),"Yes")
Again use Ctrl-Shift-Enter.
Thank you as well J.Ty. for your help - formula works perfectly.
Great community here :)
 
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
just for fun, is that what you want to achieve?
componentlcomponent2totalcomponentlcomponent2Sum
yesyes23yesyes121
nono43yes88
nono54
yesyes23
yesno42
yesyes75
noyes12
noyes5
yesno88
 
Upvote 0
Thank you once again - extremely helpful for me this formula.
Not sure which formula(s) you are referring to or have ended up using but there is a significant difference in performance if your actual range is relatively small. For example, for the sample data provided, on my machine the formula in post #3 is approx 8,000 times faster than that from post #2.
The difference between those in posts 8 & 9 is approximately 60 times.

is that what you want to achieve?
Didn't the OP already tell us in post 1?
 
Upvote 0
If performance is a concern, then the following is probably still faster:
  • Put 0 in D1
  • Put =IF(AND(A2="yes",B2="yes"),1+D1,D1) in D2 and fill all the way down
  • Use =SUMIFS(C2:C10,A2:A10,"yes",B2:B10,"yes",D2:D10,"<=3") to calculate what you want.
There is stll room for some further improvement, but you would probably see the difference only for extremely large data sizes.
 
Upvote 0
just for fun, is that what you want to achieve?
componentlcomponent2totalcomponentlcomponent2Sum
yesyes23yesyes121
nono43yes88
nono54
yesyes23
yesno42
yesyes75
noyes12
noyes5
yesno88
Yes, i've checked the data and all the formulas you've sent me worked fine.
Performance is important, datasets i'm working with are quite large.
I appreciate a lot all your replies, very helpful.
 
Upvote 0
I didn't send any formula but I can give you M-code for Power Query (Get&Transform) to get the result you Quoted
Code:
// DoubleYes
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Filter = Table.SelectRows(Source, each ([componentl] = "yes")),
    Kept3 = Table.FirstN(Filter,3),
    Group = Table.Group(Kept3, {"componentl"}, {{"Sum", each List.Sum([total]), type number}}),
    Source2 = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Filter2 = Table.SelectRows(Source2, each ([componentl] = "yes") and ([component2] = "yes")),
    Kept32 = Table.FirstN(Filter2,3),
    Group2 = Table.Group(Kept32, {"componentl", "component2"}, {{"Sum", each List.Sum([total]), type number}}),
    Append = Table.Combine({Group2, Group})
in
    Append
 
Upvote 0
I didn't send any formula but I can give you M-code for Power Query (Get&Transform) to get the result you Quoted
Code:
// DoubleYes
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Filter = Table.SelectRows(Source, each ([componentl] = "yes")),
    Kept3 = Table.FirstN(Filter,3),
    Group = Table.Group(Kept3, {"componentl"}, {{"Sum", each List.Sum([total]), type number}}),
    Source2 = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Filter2 = Table.SelectRows(Source2, each ([componentl] = "yes") and ([component2] = "yes")),
    Kept32 = Table.FirstN(Filter2,3),
    Group2 = Table.Group(Kept32, {"componentl", "component2"}, {{"Sum", each List.Sum([total]), type number}}),
    Append = Table.Combine({Group2, Group})
in
    Append
Thank you, Sandy - I think I'll stick w/ formulas, it's easier for me.
But i appreciate your help.
 
Upvote 0

Forum statistics

Threads
1,214,877
Messages
6,122,051
Members
449,064
Latest member
scottdog129

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