Display the column number of the last non-empty cell within a range (if values are not unique) - excel

I have the following Excel spreadsheet:
A B C D E F G H I J K L
1
2
3
4 600 150 80 600 0 0 4
5 200 150 80 80 0 0 4
6
7
In Range K4:K5 I currently use the formula from this question to identify the last non-empty cell within the range and get the the column number of it back:
K4 = LOOKUP(2,1/(D4:J4<>0),COLUMN(D4:J4)-MIN(COLUMN(D4:J4))+1)
K5 = LOOKUP(2,1/(D5:J5<>0),COLUMN(D5:J5)-MIN(COLUMN(D5:J5))+1)
This formula works in the simple example above. However, once I use this formula in a bigger spreadsheet I get a lot of performance issues and numbers are not always updated correctly.
Therefore, I am wondering if there is alternative formula to get the column number of the last non-empty cell no matter if the values are unique or not?

As already described in the comments below the question the following solutions are available:
Option A)
If you want to get column number of the last non-empty cell:
=AGGREGATE(14,7,(COLUMN(D4:J4)-MIN(COLUMN(D4:J4))+1)/(D4:J4>0),1)
Option B)
If you want go tet the value in the last non-empty cell:
=INDEX(D4:J4,AGGREGATE(14,7,(COLUMN(D4:J4)-MIN(COLUMN(D4:J4))+1)/(D4:J4>0),1)
=INDEX(A4:J4,AGGREGATE(14,7,COLUMN(D4:J4)/(D4:J4>0),1)

Related

Populate summary "table" column based on details "table"

I've tried looking up how this might be done, but it's a bit beyond my excel-fu, unfortunately (I could do it in SQL in a snap!).
Basically, in one worksheet, I have the following details "table" (I've included the column and row labels):
A B C D
1 owner name line # run?
2 A A1 10 Y
3 A A1 20 N
4 A A2 2 Y
5 A A2 14 Y
6 A A3 34 N
7 B B1 26 Y
8 B B1 59 Y
9 B B1 193 Y
10 B B1 194 Y
11 B B2 27 N
12 B B2 51 N
and I have the following summary "table" on a different worksheet
A B C
1 owner name status
2 A A1
3 A A2
4 A A3
5 B B1
5 B B2
I need to populate the status column in the summary "table" based on the run? column in the details "table", linked on the owner and name columns.
Here are the results I'm expecting to get, along with why:
A B C D
1 owner name expected status reason
2 A A1 Partial There are Y and N values for owner=A and name=A1 in the details table
3 A A2 Complete There are only Y values for the owner=A and name=A2 in the details table
4 A A3 Not Started There are only N values for the owner=A and name=A3 in the details table
5 B B1 Complete There are only Y values for the owner=B and name=B1 in the details table
5 B B2 Not Started There are only N values for the owner=B and name=B2 in the details table
I know I'll probably need countifs to work out if there are Y's and N's present, plus an IF to turn the output into the words, it's the getting to the point where I can count the Y's and N's present for each owner+name that I'm struggling with.
I have googled how I might find out if there were Y's and/or N's present for a given owner and name, and have come across this link which involves MATCH and INDEX but for the life of me, I can't get it working - I get an output of #N/A, using the following formula to get the first status:
=INDEX(A2:D12,0,MATCH(c2,'<Detail worksheet>'!A2:D12,0))
Am I on the right lines or is there a better way of doing this? (I could always manually specify the range of rows to look down in the details "table" for each summary "table" row, but I'd like to avoid that if possible!)
I split the formula into two parts, which should get you most of the way there. If you have an uncertain length of data, then be careful with how many rows you examine, my answer only goes to row 13.
Summary Sheet with columns added to split formula
Sheet 1
The formula for the Y column in the above picture is:
=COUNTIFS(Sheet1!$E$3:$E$13,Sheet2!$D$2,Sheet1!$B$3:$B$13,Sheet2!$B3,Sheet1!$C$3:$C$13,Sheet2!$C3)

Formula to calculate a sum of differences and count them

I have the following Excel spreadsheet:
A B C D E F G H
1 Sales 500 700 600 450 550 600 500
2 Helper Row (Differences) 40% -14% -25% 22% 9% -17%
3 Helper Row (Counts) 0 0 1 0 0 0
4 Count Result 1
In Row 1 you can see the sales over different periods. In Row 2 the difference between the sales are displayed. (e.g. formula in C2=C1/B1-1).
In Row 3 the formula indicates 2-Following-Periods in which in total the sales drop by >-20%.
In the case above this applies to cell E3 because the sales in cell D2 drop by -14% and in the next period in cell E2 by -25% which makes a total drop of those two periods by -39%.
The formula I use in Row 3 is for example E3=IF(SUM(D2:E2)<-0.2,1,0).
Eventually, I use a sum function in cell B4 (B4=SUM(B3:H3)) to count how often the above described criteria is met.
All this works perfectly so far. However, my target now is to get rid of the Hepler Row 2 and Row 3.
Do you know a formula that gives me the count result which meets the above described criteria?
Assuming that your above demonstrated numbers are in cell B1:H1, you can use following formulae to achieve result without helper cells.
Array formula (CTRL+SHIFT+ENTER and not just ENTER)
=SUM((((C1:H1-B1:G1)/B1:G1)<-0.2)+0)
Or for normal ENTER
=SUMPRODUCT((((C1:H1-B1:G1)/B1:G1)<-0.2)+0)

Dragging formulas across - Increment columns by more than 1

I can't seem to find anything similar that's already been asked (they all relate to incrementing row numbers rather than columns)
I'm looking to drag a formula across horizontally and have the columns increment by 2
E.g. B1-A1, D1-C1, F1-E1...
Thanks!
You'll need to have a value in cell A1 and B1 for the following to work.
For my testing I put the number 1 in A1 and B1.
Try this in Cell C1:
=IF(MOD(COUNT($A$1:B1),2)=0,COLUMN(B1),IF(B1<>A1,B1,A1))
Here's what you should see when you drag that formula across:
A B C D E F G H I J K L M N
1 1 2 2 4 4 6 6 8 8 10 10 12 12
And this is what the formula does:
The MOD(COUNT() part of the formula counts the cells to the left of it, and if they are a multiple of 2, the value changes.
I've left the value to change to (the 'new' value) as the COLUMN() number for the cell before, just for example's sake. but you can change this part.
The last IF statement at the end checks if the cell before is equal to the cell before that, (eg. Is CELL C1 equal to CELL B1) and if they are not equal, it will give the cell before as a value (the 'copy' value).

Find last non-zero cell's column reference in an UNORDERED range of values

I have a range with numbers in a row in Excel, say:
A B C D E F G H I J K L
Line 1 => 0 0 0 3 2 8 3 6 0 0 0 0
All cells are non-blank but some contain zeros and some contain numbers. Also, the range cannot be ordered in either ascending or descending order.
I need a formula (not VBA) that will return the column of the last non-zero value in the range (i.e. column 8 for cell H1 above). I can get the actual value of cell H1 with this formula:
LOOKUP(2,1/(A1:A10<>0),A1:A10)
but I cannot find a way to get the column number for that cell.
Any ideas?
You are very close:
=LOOKUP(2,1/(A1:L1<>0),COLUMN(A1:L1))
Enter
=MAX(IF(YourRange=0,0,COLUMN(YourRange)))
as an array formula (CTRL-SHIFT-ENTER).
For me, the best solution for numeric values was this:
=IF(D497<>0,D497,IF(D496<>0,D496,IF(D495<>0,D495,IF(D494<>0,D494,IF(D493<>0,D493,D492)))))
it gives the last non zero value, for your require range that you can make by adding further rows to the formula.

Sum the values in Excel cells depending on changing criteria

In an Excel spread sheet I have three columns of data, the first column A is a unique identifier. Column B is a number and column C is either a tick or a space:
A B C
1 d-45 150 √
2 d-46 200
3 d-45 80
4 d-46 20 √
5 d-45 70 √
Now, I wish to sum the values in column B depending on a tick being present and also relative to the unique ID in column A. In this case rows 1 and 5. Identifying the tick I use
=IF(ISTEXT(C1),CONCATENATE(A1))
&
=IF(ISTEXT(C1),CONCATENATE(B1)).
This leaves me with two arrays of data:
D E
1 d-45 150
4 d-46 20
5 d-45 70
I now want to sum the values in column E depending on the ID in column D, in this case row 1 and 5. I can use a straight forward SUMIFS statement to specify d-45 as the criteria however this unique ID will always change. Is there a variation of SUMIFS I can use?
I also wish to put each new variation of ID number into a separate header with the summed totals underneath, that is:
A B
1 d-45 d-46
2 220 20
etc...
You can try this:
To get the distinct ID's write (in H1 then copy right):
This one is an array formula so you need Ctrl Shift Enter to enter the formula
=INDEX($A$1:$A$5;SMALL(IF(ROW($A$1:$A$5)-ROW($A$1)+1=MATCH($A$1:$A$5;$A$1:$A$5;0);ROW($A$1:$A$5)-ROW($A$1)+1;"");COLUMNS($A$1:A1)))
Now to get the sum (H2 and copy right)
=SUMPRODUCT(($A$1:$A$5=H1)*ISTEXT($C$1:$C$5)*$B$1:$B$5)
Data in the example is in A1:C5
Depending on your regional settings you may need to replace ";" field separator by ","
Try this,
SUMIFS
=SUMIFS(B1:B5,A1:A5,"=d-45",C1:C5,"<>")
where "<>" means that the cell is not empty...

Resources