Returning first two values in row, including 0

BiggusDoggus

Board Regular
Joined
Jul 7, 2014
Messages
91
Office Version
  1. 365
Platform
  1. Windows
Hi all

So I have a table of data, with the columns being the months of the year. Each row has a range of data, with some or all months having values entered.

[TABLE="class: outer_border, width: 500"]
<tbody>[TR]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[TD]H[/TD]
[TD]I[/TD]
[TD]J[/TD]
[TD]K[/TD]
[TD]L[/TD]
[TD]M[/TD]
[TD]N[/TD]
[TD]O[/TD]
[/TR]
[TR]
[TD]Sales[/TD]
[TD]Jan[/TD]
[TD]Feb[/TD]
[TD]Mar[/TD]
[TD]Apr[/TD]
[TD]May[/TD]
[TD]Jun[/TD]
[TD]Jul[/TD]
[TD]Aug[/TD]
[TD]Sep[/TD]
[TD]Oct[/TD]
[TD]Nov[/TD]
[TD]Dec[/TD]
[TD][/TD]
[TD]Sum first 2 Months[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]1[/TD]
[TD]5[/TD]
[TD][/TD]
[TD]6[/TD]
[TD]8[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]6[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]3[/TD]
[TD][/TD]
[TD]4[/TD]
[TD]7[/TD]
[TD]9[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]7[/TD]
[/TR]
</tbody>[/TABLE]


What I'm wanting to be returned in column O is the sum of the values in the first two cells of each row, from the first non-blank cell. That sum needs to include if the second cell from the first non-blank is in fact blank.


The current formula in column O is

{=IFERROR(IF(SUM(B2:INDEX(B2:M2,SMALL(IF(ISNUMBER(B2:M2),COLUMN(B2:M2)-COLUMN(B2)+1),MIN(2,COUNT(B2:M2)))))>200,"",SUM(B2:INDEX(B2:M2,SMALL(IF(ISNUMBER(B2:M2),COLUMN(B2:M2)-COLUMN(B2)+1),MIN(2,COUNT(B2:M2)))))),"")}

As you can see, row 2 works fine - the first 2 values are 1 in Feb and 5 in March, so the sum is 6.
However, row 3 is not returning what I want it to. The first non-blank cell has a value of 3, and the next cell is blank, so I want it to return 3 as the sum.

What it's doing is ignoring any subsequent blank cells after the first non blank.

I didn't write the existing formula (it's far too complex for me to have written with my current relatively limited Excel knowledge) so I don't know how to amend it.

Any help would be greatly appreciated please!
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Try this array formula in cell O2 copied down

=INDEX(B2:M2, MATCH(FALSE, ISBLANK(B2:M2), 0))+INDEX(B2:M2, MATCH(FALSE, ISBLANK(B2:M2), 0)+1)

Confirm an array formula with {Ctrl}{Shift}{Enter}
 
Upvote 0
Much more concise, too.
.. or more so ..
{=SUM(B2:INDEX(B2:M2, MATCH(FALSE, B2:M2="", 0)+1))}

.. or not so concise, but not requiring the Ctrl+Shift+Enter
=SUM(B2:INDEX(B2:M2,AGGREGATE(15,6,(COLUMN(B2:M2)-COLUMN(B2)+1)/(B2:M2<>""),1)+1))

One further comment, that apparently isn't relevant to the OP but may be to other readers: The post 2 formula requires the blank cells to be truly blank and not filled by formula returning "". The formulas in this post do not.
 
Upvote 0
One further comment, that apparently isn't relevant to the OP but may be to other readers: The post 2 formula requires the blank cells to be truly blank and not filled by formula returning "". The formulas in this post do not.

and the post 2 equivalent...

=INDEX(B2:M2, MATCH(FALSE, B2:M2="", 0))+INDEX(B2:M2, MATCH(FALSE, B2:M2="", 0)+1)
 
Upvote 0
{=SUM(B2:INDEX(B2:M2, MATCH(FALSE, B2:M2="", 0)+1))}

Why do we convert a formula into array by pressing ctrl shift entr.
What changes between it being a simple formula and being an array formula
 
Upvote 0
{=SUM(B2:INDEX(B2:M2, MATCH(FALSE, B2:M2="", 0)+1))}

Why do we convert a formula into array by pressing ctrl shift entr.
So that it works? :)


What changes between it being a simple formula and being an array formula
Without the array entry the blue part returns an error & therefore so does the whole formula. With the array entry the blue part compares each indiviual cell in the range to "" and returns an array of 12 TRUE/FALSE results which is used by the MATCH function.
 
Upvote 0

Forum statistics

Threads
1,223,706
Messages
6,173,998
Members
452,542
Latest member
Bricklin

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