Sum of first n from m cells

jshah

New Member
Joined
Nov 17, 2009
Messages
7
Hi,

Using excel formulas, how do find an sum of first n values of an array? Each cell in the array may or maynot contain a number, ignore non-numbers in an array? If n is greater than count of number then add all numbers present in the array.

In each case I would like to find the count of numbers that were added.

example
The array (column) contains numbers OR a letter "Y". eg
1,45,Y,32,56,Y,12,Y,Y,16,18.

if n = 2 ,then I want to calculate sum of 1 and 45, and count to return 2.

if n = 3 , then I want to calculate sum of 1,45 and 32 (ignoring "Y") and count to return 3.

if n = 7 ,then I want to calculate sum of 1,45,32,56,12,16,18 (ignoring "Y") and count to return 7.

if n = 9 ,then, I want to sum of 1,45,32,56,12,16,18 (ignoring "Y") and count to return 7 (in this case return count is < n).

if possible I do not want add any extra rows or coloums in the spread sheet to store intermediate data.

Thanks for the help.:)
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Thank you very much.
Perfect answer in a few mins of asking the question, much appreciated :)
 
Upvote 0
Thank you very much.
Perfect answer in a few mins of asking the question, much appreciated :)
In that case, did you ask the wrong question or give incorrect examples?

if n = 3 , then I want to calculate sum of 1,45 and 32 (ignoring "Y") and count to return 3
This sum would be 78 and you have stated the count should be 3. However, the suggested formulas (E6:H7 below) return 46 and 2 for this example.

I know you said you didn't want any extra columns but I have used one. If it is to be removed, I think the remaining formulas would become much more complicated.

Anyway, I think with formula in D1, copied down, and formulas in E3:E4, copied across, you get the results indicated in your examples.

Excel Workbook
ABCDEFGH
2112379
34524678180180
4Y22377
5323
65644646146146
7Y42255
8125
9Y5
10Y5
11166
12187
Sum first n
 
Upvote 0
Hi peter,
Thank you very much, i agree the original answer suggested by Aladin Akyurek is not correct as the per the question.

Is there a way I can getting the answer without creating the "D" column in your answer. My spread sheet has over 1000 rows and I would like if possible, to find answer which does not involve creating of extra row for every row I have in the table.

Never the less, I appreciate, you sending a correction and sugguestion a solution that works in practice.

thanks
jshah
 
Upvote 0
Hi peter,
Thank you very much, i agree the original answer suggested by Aladin Akyurek is not correct as the per the question.

Is there a way I can getting the answer without creating the "D" column in your answer. My spread sheet has over 1000 rows and I would like if possible, to find answer which does not involve creating of extra row for every row I have in the table.

Never the less, I appreciate, you sending a correction and sugguestion a solution that works in practice.

thanks
jshah
The formula in E3 is an array formula so should be entered without the {} but confirmed with Ctrl+Shift+Enter, not just Enter. If confirmed correctly, Excel will insert the {}. The formula can then be copied across.

Excel Workbook
ABCDEFGH
1
21n:2379
345Sum:4678180180
4YCount:2377
532
656
7Y
812
9Y
10Y
1116
1218
13
Sum first n
 
Upvote 0
Hi Peter,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
thank you. Superb use of array formulas.I did not know of their existence. I am decomposing your suggested answer to unravel the working.
JShah<o:p></o:p>
 
Upvote 0

Forum statistics

Threads
1,215,025
Messages
6,122,734
Members
449,094
Latest member
dsharae57

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