How to ensure list of numbers in excel column continues from the last non zero number - excel

Imagine 3 columns, Column A and Column B and Column C.
Column A is a date column.
Column C is lookup column that looks up a value from 1 - 100 from a different table based on the date.
Column B is continuation of values from 0 from the first date value and continues with the value until the value in column c changes.
How do you formulate column B so it automatically keeps the last non zero value until another value in column C appears?
Column A
Column B
Column C
01/01/2021
0
0
02/01/2021
0
0
03/01/2021
0
0
04/01/2021
20
20
05/01/2021
20
0
06/01/2021
20
0
07/01/2021
50
50
08/01/2021
50
0
09/01/2021
50
0

Either
=IFERROR(LOOKUP(2,1/(C$1:C1<>0),C$1:C1),0)
Or;
=XLOOKUP(TRUE,C$1:C1<>0,C$1:C1,0,0,-1)
Or, if these values are always bigger then the last one:
=MAX(C$1:C1)

You can do it as a spill formula in Excel 365 too:
=LET(range,C1:C9,
seq,SEQUENCE(ROWS(range)),
XLOOKUP(seq,IF(range>0,seq),range,0,-1)
)

Related

Formula to Find if Number between a Range in 2 Columns and then Offset 1 column

I would like to write an Excel formula that looks at 3 columns and grabs value of the 1st column based on if the search value is in columns 2 or columns 3.
1st Column 2nd Column 3rd Column
a 1 5
b 6 10
c 11 15
Search Value 1: 13 Result: c
Search Value 2: 6 Result: b
Try below formula-
=INDEX($A$1:$A$3,MAX(($B$1:$B$3<=B6)*($C$1:$C$3>=B6)*(ROW($A$1:$A$3))))

Use value in cell as index for row in Excel SUM function

Given the two worksheets below, I want to put a SUM in Column F for each row but instead of SUMMING the values in Sheet1, I need to use the cell value in Sheet1 as the row number in Sheet2 and use those cell values in the SUM. For example, the SUM for Bill should be SUM(Sheet2! B1,C6,D4,E3) = 200.
Sheet1
A B C D E F
Bill 1 6 4 3 200
Sue 2 1 3 2 450
Mary 3 2 2 1 550
Joe 4 3 1 4 150
Alice 5 4 25
Bob 6 5 0
Sheet2
A B C D E
1 100 200 50 400
2 50 100 25 200
3 25 50 0 100
4 0 25 0 50
5 0 0 0 0
6 0 0 0 0
This is just a sample spreadsheet; in the real one there are already 40 columns with more being added as necessary.
In Sheet1!F1:
=SUMPRODUCT(N(OFFSET(Sheet2!$A$1,B1:E1-1+(B1:E1-1<0)*(2^20-1),COLUMN(B1:E1)-1)))
Copy downwards as necessary.
The cells Sheet2!1048576:1048576 should not have content. Because those cells will be referenced if the row number given in Sheet1 is 0 or empty.
With the data to be summed in Sheet2!A1:E6, use this formula in Sheet1's first row's column F.
=SUM(INDEX(Sheet2!B:B, B2)*SIGN(B2), INDEX(Sheet2!C:C, C2)*SIGN(C2), INDEX(Sheet2!D:D, D2)*SIGN(D2), INDEX(Sheet2!E:E, E2)*SIGN(E2))
A zero or blank in Sheet1 would mean the entire column but that is multiplied by the SIGN function of that cell's value. Anything multiplied by zero equals zero and that will not impact the overall sum.
      
Using the INDEX function with the cell's value supplying the row_num parameter allows you to avoid volatile¹ functions that would negatively impact the calculation lag of the workbook.
¹ Volatile functions recalculate whenever anything in the entire workbook changes, not just when something that affects their outcome changes.

Excluding empty cells ("") from ascending list with Index function

I have the following Excel table:
A B C
1 Boris 4 *
2 Anna 6 *
3 Uli 5 *
4 Inge 4 *
5 Rudi 3 *
6 Ulla 7 *
7
8
9
:
:
99
*In cells C1 to C6 I am using the matrix formula:
={INDEX(A:A;VERGLEICH(KKLEINSTE(B$1:B$99-ZEILE($1:$99)/9^9;ZEILE(A1));B$1:B$99-ZEILE($1:$99)/9^9;0))}
to get the list sorted by names from the smallest to the the highest number according to column B.
The issue is now that my list has 99 rows (as you can see in the table) but not all of them are filled (as you can see in row 7 - 99 in the table).
Therefore, the formular in cell C1 to C6 shows now the value 0 because "" (empty cell) is the smallest value in the list from B1 to B99.
How do I have to change the formular that it considers all values in column B except for the cells that are empty? (Note: If a cell in column B has the value 0 it should be considered. Only when the cell is empty it should be excluded)
Thanks for any help :-)
Just add a condition to check for numericalness:
=INDEX(A:A,MATCH(SMALL(IF(ISNUMBER(B$1:B$99),B$1:B$99-ROW($1:$99)/9^9),ROWS($1:1)),B$1:B$99-ROW($1:$99)/9^9,0))
In German:
=INDEX(A:A;VERGLEICH(KKLEINSTE(WENN(ISTZAHL(B$1:B$99);B$1:B$99-ZEILE($1:$99)/9^9);ZEILEN($1:1));B$1:B$99-ZEILE($1:$99)/9^9;0))
I have replaced ROW (ZEILE) with ROWS (ZEILEN) as it is a more rigorous choice for SMALL's k parameter:
http://excelxor.com/2014/08/25/row-vs-rows-for-consecutive-integer-generation/
Regards

Displaying column headers based on value their columns hold

Using Excel 2013. I require a formula to check if a range of cells in columns are 0, then the header should be displayed in a single cell. For example, for Product 1 only B, C, D should be displayed, for Product 2 E, F, H should be displayed, and in only a single cell:
Product A B C D E F G H
Product1 0 0 0
Product2 0 0 0
Product3 0 0 0 0
Is it possible?
If Product is in A1, please try in J2 and copied down to suit:
=IF(NOT(ISBLANK(B2)),B$1,"")&IF(NOT(ISBLANK(C2)),C$1,"")&IF(NOT(ISBLANK(D2)),D$1,"")&IF(NOT(ISBLANK(E2)),E$1,"")&IF(NOT(ISBLANK(F2)),F$1,"")&IF(NOT(ISBLANK(G2)),G$1,"")&IF(NOT(ISBLANK(H2)),H$1,"")&IF(NOT(ISBLANK(I2)),I$1,"")
A similar approach could be much shorter had the indictors been almost anything other than 0.

Excel Find Value next to max value

If I do a simple formula such as
=MAX(J:J)
and I have a table such as
1 2
2 10
3 45
4 1
5 144
I would expect to see my cell = 144
is there a way for me to get the result 5 (as in the column to the left of the max?)
So if you want the value from column I try this formula
=INDEX(I:I,MATCH(MAX(J:J),J:J,0))
MATCH finds the relevant row number then INDEX gives you the value in column I from that same row

Resources