Column name of last non zero value in row in Excel - excel

How I can get column name of last non zero value in row, using Excel functions.
Example:
A:E - columns with values
x - function result
A B C D E x
0 0 1 0 0 C
1 0 2 1 2 E
0 1 1 0 1 E
1 1 1 1 1 E
0 0 0 0 0

This works:
=IFERROR(CHAR(AGGREGATE(14,6,COLUMN(A1:E1)/(A1:E1<>0),1)+64),"")

Enter with CTRL + Shift + Enter:
=IFERROR(MID(ADDRESS(ROW(),MAX(IF(A2:E2,COLUMN(A2:E2)))),2,SEARCH("$",ADDRESS(ROW(),MAX(IF(A2:E2,COLUMN(A2:E2)))),2)-2),"")

These are array-formulas that must be entered using CTRL+SHIFT+ENTER:
This works up to ZZ:
=IFERROR(SUBSTITUTE(MID(CELL("address",OFFSET(A1,0,MAX(IF(A1:AA1<>0,COLUMN(A1:AA1),0))-1)),2,2),"$",""),"")
This works for all columns:
=IFERROR(MID(CELL("address",OFFSET(A1,0,MAX(IF(A1:AAA1<>0,COLUMN(A1:AAA1),0))-1)),2,FIND("$",MID(CELL("address",OFFSET(A1,0,MAX(IF(A1:AAA1<>0,COLUMN(A1:AAA1),0))-1)),2,99))-1),"")
Update: The accepted answer is more efficient. It assumes numeric values but could be easily updated to handle non-numeric values as well. However it could be optimised further:
=IFERROR(MID(SUBSTITUTE(ADDRESS(1,MAX(IF(A2:XED2,COLUMN(A2:XED2)))),"$1",""),2,3),"")

Related

excel extendable formula for conditional sums over multiple columns

I have an arbitrary number of columns, one for each period a course is offered, in chronological order, and an arbitrary number of rows, one for each unique participant. The values are '1' for participation in that month, '0' for non-participation.
Fall2019 Spring2019 Fall2018 Spring2018 Fall2017
1 1 0 1 0
0 1 1 1 1
0 1 1 1 1
0 1 1 1 1
0 1 0 1 1
0 1 1 0 0
0 1 1 0 0
0 1 1 0 0
1 0 0 0 0
I would like to take a sum, at the bottom of each column, for how many participants were first time attendees that period, i.e. the sum of '1's where all values in the row to the right of that '1', are '0'.
In the given example set, Spring2018 should sum to 1, Fall2018 should sum to 3.
Something like the formula below will work for 'Spring2018' when there is just one previous column to compare:
=SUMPRODUCT((D2:D9)*(E2:E9=0))
But this formula cannot be 'autofilled' or extended across multiple columns... i.e. none of these variations work:
=SUMPRODUCT((C2:C9)*(D2:$E9=0))
=SUMPRODUCT((C2:C9)*(SUM(D2:$E9)=0))
=SUMPRODUCT((C2:C9)*(SUMIF(D2:$E9,"0")))
And while it will work, I do NOT want to have to manually create extended versions of this formula e.g.
=SUMPRODUCT((C2:C9)*(D2:D9+E2:E9=0))
=SUMPRODUCT((B2:B9)*(C2:C9+D2:D9+E2:E9=0))
... and so on
I have tried several variations on arrayformula, sumproduct, and sumif, but I'm really stuck. Any assistance is appreciated.
use this array formula:
=SUM(A2:A10*(MMULT(--(B$2:$E$10=1),TRANSPOSE(COLUMN(B$2:$E$10)^0))=0))
Being an array formula it must be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.

Excel: sum a number for every colum that contains a number

I have a basic excel spreadsheet like this:
A B C D etc..
1 1 0 0 etc..
0 0 1 1 etc..
0 0 1 1 etc..
I would like to SUM 100 for every cell that contains 1 in one Cell and to SUM 100 por every cell that contains 0 in other cell.. How can i do this?
I hope you understand my question, english its not my first language.
It looks as if the answers might be
=COUNTIF(A1:D10,1)*100
and
=COUNTIF(A1:D10,0)*100
(change the ranges as necessary)

Count all cells after the first non zero value found - Excel?

I have this example:
I need a formula to count all the numbers after the first aparition of a non zero value.
The Values range is A1:H4. But i need count for every line A1:H1; A2:H2...A4:H4.
0 0 7 2 0 0 0 9 - result of numbers counted 6
5 0 4 0 2 0 0 0 - result of numbers counted 8
0 0 0 0 0 0 7 0 - result of numbers counted 2
0 0 0 0 0 0 0 4 - result of numbers counted 1
Thank you!
c
If the values are in A1:H1, array formula**:
=COUNT(H1:INDEX(1:1,MATCH("",T(1/A1:H1),0)))
To take an example: with A1:H1 containing:
0 0 7 2 0 0 0 9
the reciprocation:
1/A1:H1
will return:
{#DIV/0!,#DIV/0!,0.142857142857143,0.5,#DIV/0!,#DIV/0!,#DIV/0!,0.111111111111111}
Applying the T function to this array returns:
{#DIV/0!,#DIV/0!,"","",#DIV/0!,#DIV/0!,#DIV/0!,""}
i.e. all non-zeroes in the original range have now been reduced to the null string ""; all zeroes to an error.
We can now perform an exact match for the null string, such that:
MATCH("",T(1/A1:H1),0)
which is:
MATCH("",{#DIV/0!,#DIV/0!,"","",#DIV/0!,#DIV/0!,#DIV/0!,""},0)
gives:
3
And so:
INDEX(1:1,MATCH("",T(1/A1:H1),0))
which is:
INDEX(1:1,3)
returns a range reference to the cell:
C1
and so, finally:
COUNT(H1:INDEX(1:1,MATCH("",T(1/A1:H1),0)))
which is:
COUNT(H1:C1)
in which Excel will correct the range reference to:
COUNT(C1:H1)
is:
6
as required.
Regards
**Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).
=LEN(RIGHT(A1,FIND("1",A1&"1")))

What is wrong with formula: =IF(A1>B4:D4,1,0)?

Question 1
What is wrong with formula?
=IF(A1>B4:D4,1,0)
I want if cell A1 is greater than set of cells (B4:D4) then it returns 1.
Answered
Question 2:
How can i select/indentify two MAX values from set of cells? I want to count two max values.
For example:
(header) A B C D E
(row1) 1 5 4 1 3
It should return
(header) F G H I J
(row1) 0 1 1 0 0
For top 2 values I would use the LARGE function
=IF(A1>LARGE(B4:D4,2),1,0)
The LARGE function returns the nth largest value, so LARGE(B4:D4,1) would be equivalent to MAX(B4:D4), but LARGE(B4:D4,2) returns the 2nd largest value
I guess you mean bigger than the max of them:
=IF(A1>MAX(B4:D4),1,0)

excel formula depending on dynamic values in different columns

I am trying to create an excel formula using SUM and SUMIF but cannot find how to.
I have a first column(A) which is the total time of a piece of work and then for each row the time spent in that task during each day(columns B, C, ...).
For each day(columns B, C, ...), the formula would return the sum of only those values in column A that(for that specific column), relate to task that have been completed that day: the sum of all cells within a row is equals or more than the time the task was allocated.
Example for one 12-hours task:
A B C D E
12 4 6 2 0
Using the formula:
A B C D E
12 4 6 2 0
0 0 0 12 0
where 12 is displayed in column D because 4 + 6 + 2 = 12(Column A)
Second example(3 tasks):
A B C D E
10 9 0 1 0
21 8 8 5 0
5 0 0 3 2
Using the formula:
A B C D E
10 9 0 1 0
21 8 8 5 0
5 0 0 3 2
0 0 0 31 5
Where:
31(Day D) = 10(Task 1 is finished that day) + 21(Task 2 is finished that day too)
5(Day E) = Task 3 is finished that day
Tried this formula (for Day B):
SUMIF(B1:B3,">=A1:A3",A1:A3)
(Sum those values in column A if the cells in that row p to column B(in this case just B) are >= than those iterated).
Then for column C, it would be,
SUMIF(C1:C3 + B1:B3,">=A1:A3",A1:A3)
The above examples did not work(first returns zero, second is an invalid formula),
Any ideas?
Thank you.
Formula below given by user ServerS works fine:
Col B:
=IF(SUM(B2)=A2,A2,0)+IF(SUM(B3)=A3,A3,0)+IF(SUM(B4)=A4,A4,0)+IF(SUM(B5)=A5,A5,0)
Col C:
=IF(SUM(B2:C2)=A2,A2,0)+IF(SUM(B3:C3)=A3,A3,0)+IF(SUM(B4:C4)=A4,A4,0)+IF(SUM(B5:C5)=A5,A5,0)
Col D
=IF(SUM(B2:D2)=A2,A2,0)+IF(SUM(B3:D3)=A3,A3,0)+IF(SUM(B4:D4)=A4,A4,0)+IF(SUM(B5:D5)=A5,A5,0)
However there are two inconvenients:
if new rows are added it needs to be adapted and include another IF(). Would be better to have a generic SUM if IF's
Trying to propagate the formula to adjacent cells is not possible as it would change part of the formula like "=A2,A2,0" to "=A3,A3,0" which needs to keep the same.
Any other ideas that improve this, if possible, are appreciated.
You can avoid using IF with a sumproduct. This method allows use to insert any row you want. Make sure range are correct (eg A2:A5 with 5 the last row used). I would go for this :
in column B :
=SOMMEPROD(($A$2:$A$5)*($A$2:$A$5=(B2:B5)))
in column C :
=SUMPRODUCT(($A$2:$A$5)*($A$2:$A$5=(B2:B5+C2:C5)))-B6
in column D
=SUMPRODUCT(($A$2:$A$5)*($A$2:$A$5=(B2:B5+C2:C5+D2:D5)))-C6-B6
in column E
=SUMPRODUCT(($A$2:$A$5)*($A$2:$A$5=(B2:B5+C2:C5+D2:D5+E2:E5)))-D6-C6-B6

Resources