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

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.

Related

Subtract cells when the condition matches in a Row

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)

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

Add page series to every second row

I have list of ID extracted from different page numbers. I wanted to add page number to every second row in Excel as shown below:
ID Number | Page Number
1 | 1
2 | 1
3 | 2
4 | 2
5 | 3
6 | 3
7 | 4
8 | 4
9 | 5
10 | 5
Is there any way to do it?
simply use in column B1:
=TRUNC((ROW()-x)/2)+1
while x is the row to start with
Or when matching with ID:
=TRUNC((A2-1)/2)+1
and then auto-fill down (in second case, A2 is the ID to that page -> order of ID's doesn't matter)
If you put values in the first 2 Page number rows then set the 3rd row to be the value of the first row, this forumla can be copied for all remaining rows
| |A|
|1|1|
|2|1|
|3|=A1+1|
|4|=A2+1|
|5|=A3+1|
Enter the following formula into cell B2 and copy down the column:
=ROUND(A2/2, 0)
where A2 is a value from the ID Number column.

Excel: Arrange Rows to Match Another Row

I have a database with a column A with some values, and then 2 additional columns: Column B contains a bunch values that will match the ones in column A, but are not in order. I also have a Column with information that pertains to that specific row, amnd would like it to stay in 'sync' with column B. For example:
| A | B | C |
1 3 A
2 1 F
3 2 D
4 5 R
5 4 P
I'd like a way to sort it so my result would be:
| A | B | C |
1 1 F
2 2 D
3 3 A
4 4 P
5 5 R
Is there a way to do this?
If possible, if there is no match, delete the row?
In Excel 2007/2010,
simply select the cell with the "B" in it and go to the Data tab along the top and click on the A to Z button which is near the middle of the data tab. As long as B & C are adjacent columns, they will sort according to your needs. Please Note, Column A must not be adjacent to the other 2, otherwise you would run through the same procedure above but you would highlight columns B and C and perform the same sort button steps. If it gives you a Sort Warning, click the "Continue with the Current Selection" radio button and OK.

Resources