Max of prior n cells truncating to first row - excel

Say I have 1000 rows and 1 column (e.g. A1:A1000) of data. I want to define a column in a new column B such that it contains the maximum value of n prior cells (e.g. 5) in A including current row.
The part I'm having trouble with is defining the cell range such that it doesn't produce a #REF! error at first rows (first 4 rows in this example).
So as a simple example
A B
1 3.0 3.0 #REF!
2 1.1 3.0 #REF!
3 0 3.0 #REF!
4 2.5 3.0 #REF!
5 2 3.0 =MAX(A1:A5)
6 1 2.5 =MAX(A2:A6)
7 4 4 =MAX(A3:A7)
...
I tried for any 'B' cell "=MAX(A3:A7)" (in row 7) but when I copy it to cell 2 for example it displays a REF error (probably because the range went off the top).
I don't want to have to manual enter the truncated ranges in the first rows - in actuality there'd be 100s.

With INDEX and some math:
=MAX(A1:INDEX(A:A,MAX(ROW()-4,1)))

Related

Removing several desired rows from excel sheet using the second sheet

How can I remove specific rows which has the same values in another excel sheet? of course there are many columns but I filter such that specific rows remained in the second sheet and we have those values in first sheet as well as other values. for example below I want to delete rows from second set with the same value in the first column of second set. rest does not matter
A B C
1 2 3
4 5 6
7 8 9
10 1 1
second set
A B C
1 5 6
3 3 9
7 7 6
This checks if the value in A2:A4 is in the other sheet in the A-column:
Formula used (I replaced the ´;´ with ´,´)
ISNUMBER(XLOOKUP(A2,Sheet2!$A:$A,Sheet2!$A:$A,"NOPE"))
The only thing left to do is filter by color and delete the rows. Though do remember that deleting rows in larger quantities, if they're not continuous, can be quite slow.

Excel formula to return last xth numeric value from row

I have a data set like this:
a 1 2 3 5 6 7
b 5 1 3 4
c 7 4 3 2 6
d 1 2 3 7
e 7 5 5 6 7
which i want to transform in excel to only show the last 4 numeric values for each row, i.e.
a 3 5 6 7
b 5 1 3 4
c 4 3 2 6
d 1 2 3 7
e 5 5 6 7
Ive managed to use =INDEX(row1,MATCH(9.99999999999999E+307,row1)) which correctly returns the last value (i.e. 7 for row1 in this case) but how could i get the 2nd last, 3rd last, 4th last etc?
With a in A1, in M1 copied across and down to suit:
=MID(RIGHT($B1&$C1&$D1&$E1&$F1&$G1&$H1&$I1&$J1,4),COLUMN()-12,1)
then hide ColumnsB:L.
(Only works for single digits, as shown. Recent versions of Excel may offer better options.)
So I managed to figure out how to do this generically for any digits:
Say your original numerical data is in cells D5:N9.
OPTIONAL:
If any of the rows of data contain the same value twice create a copy in cells D13:N17 which amends duplicates slightly by using in D13 and dragging to fill
=IF(D5="","",D5+0.0001*(COUNTIF($D5:D5,D5)-1))
Then in cells A13:A17 enter values 13,14,15,16,17
and in cells A20:A29 enter values D, E, F, G, H, I, J, K, L, M
In Cell D20 you can return the last from row 13 value using:
=LOOKUP(9.99999999E+307,D13:N13)
and copy this down for each row.
In Cell E20 you can return the 2nd last entry using
=LOOKUP(9.99999999E+307,$D13:INDIRECT(CONCATENATE(INDEX($A$20:$A$29,MATCH(D20,$D13:$N13,0)-1),$A13)))
and copy this down for each row and drag it across to H24 to fill in all the values for 3rd last, 4th last and 5th last for each row.

I want range for specific value in excel

I want range for specific value in excel as,
my values
1
2
3
4
5
6
7
8
9
10
and suppose compare value is 2.5. If 2.5 is value then it should return range 2 and 3 in separate row for further calculations. Similarly i input value is 5.2 then it should return range 5 and 6 in separate row for further calculations
Cell E6 is the place where you have enter the value
=IFERROR((--LEFT(E6,1))&"-"&(--LEFT(E6,1)+1),"0-0")
if entered value is 5.5 the output will be 5-6

Dynamically change row number in excel

I got a file in excel that often changes the row number (My first column) whenever there is a insertion of data. However, there is multiple rows of data with the same row number.
Example:
1
1
2
3
3
3
Is there a way I can change them dynamically beside grouping the number together via Filter and change it manually?
Edited.
1
1
1
2
3
4
4
4
Better example. Sorry about the indentation.
I can propose a partial solution.
Set the value only in the first identical value and change only those unique values when a group of rows is inserted:
1 1
1 =A1
1 =A2
2 2
3 3
4 4
4 =A6
4 =A7
Otherwise, you do it from VBA to change all values when a new row is inserted.

Find maximum of row, return column name

I have four rows and six columns of random numbers between 1 and 10. The headers atop are named A through F accordingly. I want to populate a range (A1:A6) on another sheet with the maximum number for each row. That is easy with the MAX function. However, in a another range (B1:B6), I want to put the column name to which this number belongs.
An HLOOKUP() won't work because a maximum value in one row is likely not unique number across the entire sheet. I am thinking a MATCH INDEX type function, but my understanding of those functions, especially in conjunction, is poor.
A B C D E F
1 0 2 10 9 8
9 3 7 6 9 10
10 3 0 2 1 4
9 4 7 8 6 3
Assuming your array is in Sheet1 and the columns are labelled, please try in another sheet, copied down to suit (to Row4 since there are only four rows of numbers in your data):
=INDEX(Sheet1!A$1:F$1,MATCH(MAX(Sheet1!A2:F2),Sheet1!A2:F2,0))
This will return only the first column label from a row where the maximum for that row occurs more than once.

Resources