Sum the result of every 2 rows, if the result is negative - excel

I have a single column of numbers, I need to sum row 1 and row 2, sum row 3 and row 4, all the way to the end of column. And then, I need to sum all the previous result if the result is negative only.
I can only do this series of adding without creating more columns because I have to to this for many columns and I don't want to create another column to store the sub result as that will double the number of columns.
Any way I can achieve this with excel formula? Thanks.

In B2, formula copied down :
=IFERROR(1/(1/SUM(OFFSET($A$1,(ROW(A1)-1)*2+1,0,2))),"")
Edit #.1
In A10, enter formula :
=SUMPRODUCT(0+TEXT((A2:A8*MOD(ROW(A2:A8)-1,2))+(A3:A9*MOD(ROW(A2:A8)-1,2)),"\0;-0"))

another SUMPRODUCT version:
=SUMPRODUCT(--TEXT(ISEVEN(ROW(A2:A8))*(A2:A8+A3:A9),"\0;-0;0"))

Related

I need a function to get desired column by matching other column values

I have two tables.
Table 1
Table 2
Now I want a function to compare Test column and when they are equal (for example row 2 of table matches row 3 and 4 of table 2) I need to compare the price column to check the max (in this example row 3 600 is greater than row 4 550) and then return my chosen column. So this should return "pixel as Value1" and "4 as rank".
I tried VLOOKUP, IF but was not able to merge them to get the desired result. Any help is appreciated.
If you have Excel-365 they could use FILTER() and SORT() function with INDEX(). Try-
=IFERROR(INDEX(SORT(FILTER($E$9:$G$12,$D$9:$D$12=$A2),3,-1),1,COLUMN(A$1)),"")
Quite similar to #Harun's answer, but I used:
Formula in B2:
=IFERROR(INDEX(SORT(FILTER(E$2:H$5,E$2:E$5=A2),4,-1),{2,3}),"")
In case you don't have Excel-365, you could do like this.
My formula in cell B3 is:
=INDEX($B$14:$B$17;MATCH(A3&SUMPRODUCT(MAX(--($A$14:$A$17=A3)*$D$14:$D$17));$A$14:$A$17&$D$14:$D$17;0))
Formula in cell C3 is almost the same, just change first argument on INDEX to retrieve Rank column:
=INDEX($C$14:$C$17;MATCH(A3&SUMPRODUCT(MAX(--($A$14:$A$17=A3)*$D$14:$D$17));$A$14:$A$17&$D$14:$D$17;0))
Notice both formulas are array formulas so they must be entered pressing CTRL+SHIFT+ENTER or it won't work!
Also, if the test is not found, it will raise an error. For example, now with values a and d won't work because those values are not present in Table2.
Here's another option if you're not running Excel 365
=INDEX($H$2:$H$5,MATCH(AGGREGATE(14,4,($G$2:$G$5=A2)*$J$2:$J$5,1),$J$2:$J$5,0))
and
=INDEX($I$2:$I$5,MATCH(B2,$H$2:$H$5,0))
The formulas above are in cells B2 and C2, as per the image below

Dynamic SUM or SUMIF Formula

I want to get the SUM of the first column IF the next column has data. In this example, the second column has data for the first 6 rows, therefore the sum that I want to get is the sum of the first 6 numbers in column 1. How the second column gets its data is chronological, so there will be no skipped cells.
You could use this formula:
=SUMIFS(A:A,B:B,">0")
It will sum the numbers in the first column, if the corresponding letters in the second column are greater than zero. Let me know if this does not cover all of your criteria, I'm sure I can help.
Thanks.

Excel: Formula or function to sum up the column values starting from a certain row

Is there a way (formula or function) in Excel (using AB or RC format) to sum the column values from a certain row (say row 5) and beyond?
I am trying to place a totals row (say on row 2) above the header (which is on row 4), and each column in the totals row displays the sum of the respective column - all rows from row 5 (which is after the header).
Your help is appreciated.
It's unclear why a simple SUM function won't work here. If you want to be fancy, try something like the following.
=sum(a5:index(a:a, match(1e99, a:a)))
Fill right as necessary.
Assuming I understand your question, so why don't you just write (in location X2, i.e. column X row 2)
=SUM(X5:X25)
Which will give you the sum of column X rows 5 to 25
Does SUBTOTAL solve your issue?
=SUBTOTAL(9, B5:B1000)
9 code for SUM
B5 is the the first cell after the header
You can use the offset function for things like this
=SUM(OFFSET(A2,3,0,995))
where the 995 is the number of rows you want to sum. You can use a count() or something instead of hardcoding it.

A formula in Excel to count the number of rows where there is a date in column 'K' but column 'N' is blank?

I am a little rusty to say the least and in Excel I would like to create a formula that counts the number of cases that have been closed without a certain stage taking place.
So, the formula would need to count the number of rows where there is a date in column k, but no date in column n (the cell is blank). Any help would be appreciated. I have had a go with COUNTIFS and SUMPRODUCT but I'm not getting anywhere.
Try this
=COUNTIFS(K:K,">0",N:N,"")
that's counting rows where K is greater than zero but N is blank [""]
If you can use another column try this formula, for every row of the column:
=IF(K1>0,1,0)*IF(N1="";1;0)
then you have to sum column values.
Instead of K1>0 you can use two cell for date so you can count cells within a range of date.
For a start try something like:
=SUMPRODUCT((K1:K100<>"")*(N1:N100=""))

How to sort table using function/equation only

How can I sort a table in sheet 1 like
A B C D E
3 7 3 6 5
into another table in sheet 2
A C E D B
3 3 5 6 7
by using function only?
One really easy way to do it would be to just have a rank index and then use HLOOKUP to find the corresponding values:
=RANK(A4,$A$4:$E$4,1)
=IF(COUNTIF($A$1:A$1,A1)>1,RANK(A4,$A$4:$E$4,1)+COUNTIF($A$1:A$1,A1)-1,RANK(A4,$A$4:$E$4,1))
=HLOOKUP(COLUMN(),$A$2:$E$4,2,FALSE)
=HLOOKUP(COLUMN(),$A$2:$E$4,3,FALSE)
Okay, here's the "one formula does it all" solution without additional temporary columns:
Formula in A6:
=INDEX($A$2:$E$2,MATCH(SMALL($A$3:$E$3+COLUMN($A$3:$E$3)/100000000,COLUMN()),$A$3:$E$3+COLUMN($A$3:$E$3)/100000000,0))
Enter it as an array formula, i.e. press Ctrl-Shift-Enter. Then copy it to the adjacent columns.
To get also the number, use this formula in A7 (again as array formula):
=ROUND(SMALL($A$3:$E$3+COLUMN($A$3:$E$3)/100000000,COLUMN()),6)
Both formulas are a bit bloated as they have to also handle the potential duplicates. The solution is to simply add a very tiny fraction of the column before applying the sorting (SMALL function) - and then to remove it again...
I think an easier solution is to use the "Large" function:
The Column functions are just an easy way to count from 5 down to 1, but a helper column may be even easier.
You can have a similar answer using the "Small" function as well.
Although I have used the "add a small number technique", I think this is the most elegant for a helper row/column:
=RANK(B4,$B$4:$F$4,0) + COUNTIF($B$4:$F$4,B4)-1
(copy across the row column) RANK gets you close and the COUNTIF portion handles duplicates by counting the number of duplicates of the cell to that point. Since there is always match (itself) you subtract 1 for the final rank. This "sorts" ties in the order that they appear. Note that an empty cell will generate #N/A and character data as #Values.
It's doable! :-)
Here is the sample file.
Explanation
I assume that your data is in row 1 of Sheet1 and that you want the data sorted starting in column 1 of another sheet - if not, adjust accordingly.
Place this formula in column 1 of the target sheet, say in row 2:
=ROUND(SMALL(Sheet1!$A$1:$E$1+COLUMN(Sheet1!$A$1:$E$1)/100000000,COLUMN()),6)
You need to enter the formula as an array formula, i.e. press Ctrl-Shift-Enter.
In case you place it in another column than column one, you need to replace COLUMN() with COLUMN()-COLUMN($A$2)+1 where $A$2must be a reference to the cell itself.
This formula will return you the lowest number in your range - if you copy it the next 4 columns, you'll get your order list of numbers.
To translate this back to the column number, we need to perform 2 steps:
Figure out the column number:This can be done with with this formula:
=MATCH(SMALL(Sheet1!$A$1:$E$1+COLUMN(Sheet1!$A$1:$E$1)/100000000,COLUMN()),Sheet1!$A$1:$E$1+COLUMN(Sheet1!$A$1:$E$1)/100000000,0)
- again, to be entered as array formula. If the source data does not start in column A, you need to add +COLUMN(Sheet1!$A$1)-1 where $A$1 needs to be replaced with the leftmost cell of the source data.
Convert the column number to a letter:Assuming your column number from step 1 is in cell A6, this formula will do the job:
=LEFT(ADDRESS(1,A6,2),SEARCH("$",ADDRESS(1,A6,2))-1)
Of course, you can also combine step 1&2, this will result in this megaformula:
=LEFT(
ADDRESS(
1,
MATCH(
SMALL(Sheet1!$A$1:$E$1+COLUMN(Sheet1!$A$1:$E$1)/100000000,COLUMN()),
Sheet1!$A$1:$E$1+COLUMN(Sheet1!$A$1:$E$1)/100000000,
0),
2),
SEARCH(
"$",
ADDRESS(
1,
MATCH(
SMALL(Sheet1!$A$1:$E$1+COLUMN(Sheet1!$A$1:$E$1)/100000000,COLUMN()),
Sheet1!$A$1:$E$1+COLUMN(Sheet1!$A$1:$E$1)/100000000,0),
2)
)-1
)
Again, to be entered as array formula.

Resources