Subtract cells when the condition matches in a Row - excel

How do I subtract horizontal multiple cells when the condition matches.
If match found then return subtracted value if not then return current value.
I tried the below formula but not able to do multiple matches
=IF(ROW(A3)=2,0,D3-D2)
Date Type Content Value Answer
1-Oct-18 Type 1 Content 1 7 7
1-Oct-18 Type 1 Content 1 7 0
1-Oct-18 Type 1 Content 1 9 2
2-Oct-18 Type 2 Content 1 8 8
2-Oct-18 Type 2 Content 2 10 10
2-Oct-18 Type 2 Content 2 3 -7

Put this in E2 and copy down:
=D2-SUMIFS($E$1:E1,$B$1:B1,B2,$C$1:C1,C2)

You do not need to check the row here as your current formula does. ROW(A3) will always return the row. Thus your test statement can be reduced to 3 = 2 which will always show TRUE
The equation you are looking for is =IF(A2=A1, D2-D1, 0)

Related

What does this formula mean in excel? (A cell equals a range)

I see the following formula in a Excel spread sheet and can not understand... Can anyone explain what the test condition "N5=N4:N741" mean?
=MIN(IF(N5=N4:N741,K4:K741))
I made some experiments and still cannot get a clue...
I'm assuming this is an array formula.
What this does is takes the minimum of the range K4:K741 where the value in N4:N741 equals the value in N5.
Let's look at a smaller example. K4:N9 is shown below.
K L M N
----------
4 | 4 2
5 | 8 7
6 | 3 4
7 | 2 1
8 | 7 9
9 | 1 7
The expression N5=N4:N9 is true in row 5 and row 9 since both of those match N5 (value = 7), giving the array {False,True,False,False,False,True} Thus IF(N5=N4:N9,K4:K9) will return {False,8,False,False,False,1} since the True values are replaced by the corresponding row in column K. The MIN() function will then ignore the False parts and return the minimum of the corresponding values in column K (the value 1 since 1 < 8).
I believe it returns an array of true and false values. I also believe the true shows up for the 3 because it is the third item in the array. but that is a guess on my part.
{false, false, true, false,false}
If you change your 5 in E1 to a 1, it will return a true.
Research all of many things excel

vlookup with multiple resulting values

I have a table array that looks like this:
A B
1 2
1 3
1 9
2 3
2 4
2 11
2 23
2 56
3 7
4 13
My VLOOKUP formula is to check for 1 in column A and then return the corresponding B value. Is there anyway I can get all the values for 1? Currently it just returns back the last corresponding number for 1 i.e. 9 in column B.
You can Pivot that data, or you can try INDEX and MATCH together, perhaps even an IF command with it.

Find summation and count only if they are EQUAL in Excel

In EXCEL sheet I have 1728 rows and 2 columns (L and O). I am doing addition of these 2 columns in column P. Further I want to count the occurrence in this column if addition is EQUAL to 2 or 4 or 6 or 8 BUT condition here is that The COUNT should be such that BOTH the columns L and O are EQUAL and Their addition is either 2 or 4 or 6 or 8.
This means that only the columns in L and O with values "1+1" , "2+2", "3+3", "4+4" should be counted. The addition of "1+3", "4+2" should not be counted.
=COUNTIF(P:P,4)
does not work.
L O P M
===========================
1 1 2 1 (NO OF 2'S)
2 2 4 1 (NO OF 4'S)
3 3 6 1 (NO OF 6'S)
1 3 4* NO TO BE COUNTED
4 4 8 1 (NO OF 8'S)
2 4 6* NOT TO BE COUNTED
4 2 6*
AS SEEN ABOVE RESULT OF COUNTING IS STORED IN M. Let me know the formula
=IF(L29=M29,SUMPRODUCT(--($L$29:$L$35=$M$29:$M$35)*(L29=$L$29:$L$35)),"Not Counted")
My data started in row 29 so you will need to adjust the references. It counts the entire table in 1 shot. So if you added a row to the bottom that had 1 and 1 and 2, the results in column M in your first row would become 2 and the same for the row you just added.
Will this formula help...?
=IF(AND(A1=B1,OR(SUM(A1,B1)=2,SUM(A1,B1)=4,SUM(A1,B1)=6,SUM(A1,B1)=8)),SUM(A1,B1),"NOT TO BE COUNTED")
Just drag the formula till you have data. You will need to adjust the references.
Here is the reference data.

Finding the first specific value above a certain cell

I'm looking for a way to find the first specific value above a certain cell.
Using the example below, in the result column every time I hit a A in COL2, I need to substract the value in COL1 to the first A value above.
The trouble seems finding a way to keep the range dynamic...
I thought of =IF(B5="A";A5-INDIRECT("A"&MATCH("A";B:B;0));"")
But of course that only works for the first one as Match will always pick up the first one.
Any ideas? Thanks!
Example :
COL1 COL2 Result
1 A
2 0
3 0
4 A 4 - 1 = 3
5 0
6 A 6 - 4 = 2
7 0
8 0
9 0
10 A 10 - 6 = 4
Try this:
=IF(AND(ROW(B2)<>2,B2="A"),A2-INDEX($A$1:$A1,AGGREGATE(14,6,ROW($1:1)/($B$1:$B1="A"),1)),"")
The AGGREGATE() Function was introduced in 2010.
In D2 enter =IF(B2="A",A2-INDIRECT("A"&MATCH("A"&(E2-1),F:F,0)),"")
In E2 enter =IF(B2="a",COUNTIFS($B$2:B2,"a"),"")
In F2 enter =B2&E2
Copy formulas from D, E and F down all your rows
Column D is the result you're looking for

How to get cells value from previous visible row in excel formulas

Is it possible to write a formulas in Excel,to calculate value based on the previous visible row?
By applying a Filter on the columns, the previous visible row changes but the usual formals does not consider visibility of the previous row, so the result does not change by applying filters. For example:
Let's original values of the spreadsheet cells be:
A | B | C | D
1: 5 3 1
2: 9 1 1
3: 2 3 0
4: 7 8 1 =A3-B4 equals 2-8=-6
Now assume that we make a filter on C column to hide the third row so we have
A | B | C | D
1: 5 3 1
2: 9 1 1
4: 7 8 1 =A3-B4 is still equals -6 but I want to get: 9-8=1
Is it possible to get such a formulas? Thank you very much.
Try this formula
=LOOKUP(2,1/SUBTOTAL(3,OFFSET(A$1,ROW(A$1:A3)-ROW(A$1),0)),A$1:A3)-B4
The SUBTOTAL/OFFSET part returns a 1 or zero for each value in column A depending on whether it's visible or not, LOOKUP finds the last 1 (equivalent to the last visible value) and gives that value.

Resources