Get last number until specific row in excel - excel

I have an excel spreadsheet that looks like this column:
id
----
1
a
b
c
2
d
e
f
3
g
h
i
1
c
d
e
2
a
d
f
Due to the fact that the numbers aren't really IDs, but group-IDs, the desired output structure is:
id | group_id
----
a | 1
b | 1
c | 1
d | 2
e | 2
f | 2
g | 3
h | 3
i | 3
c | 1
d | 1
e | 1
a | 2
d | 2
f | 2
It occurred to me that I could manipulate the formula to obtain the last non-empty value in some manner:
=LOOKUP(2,1/(B:B<>""),B:B)
I couldn't figure out how to change the internal condition to find the last digit/number value. Note: the original order is essential.
Does anyone have a suggestion?

You could produce the matching numbers for each letter using a spill formula with xlookup on the row numbers like this if you have Excel 365:
=LET(range,A1:A20,
filteredNumbers,FILTER(range,ISNUMBER(range)),
filteredNumberRowNumbers,FILTER(ROW(range),ISNUMBER(range)),
filteredLetterRowNumbers,FILTER(ROW(range),ISTEXT(range)),
XLOOKUP(filteredLetterRowNumbers,filteredNumberRowNumbers,filteredNumbers,,-1))
to get the letters themselves it's just
=FILTER(A1:A20,ISTEXT(A1:A20))

Try to apply SCAN():
Formula in C2:
=FILTER(CHOOSE({1,2},A2:A21,SCAN(0,A2:A21,LAMBDA(a,b,IF(ISNUMBER(b),b,a)))),ISTEXT(A2:A21))
Or, with access to VSTACK() and HSTACK(), to include headers:
=VSTACK({"ID","GROUP_ID"},FILTER(HSTACK(A2:A21,SCAN(0,A2:A21,LAMBDA(a,b,IF(ISNUMBER(b),b,a)))),ISTEXT(A2:A21)))

All the above answers are great. Another option that works for me is:
=LOOKUP(2,1/(ISNUMBER($A$1:A2)),$A$1:A2)
I insert that formula in B2 and use flash fill to reuse each row. Then, I filtered out the rows with letters in the A column.

Related

Excel - Get Value from 'Column A' Based on MAX of 'Column L'

I have values in column L which are the number of calls an agent has made. The agents name is in column A.
I am trying to get the max value from column L and display the name of that agent.
Here's an example of my data:
Column A | Column B | Column C | ... | Column L
Agent Name | 25-Mar-17 | 26-Mar-17 | ... | Totals
---------------------------------------------------
Kelly 5 9 ... 14
Bryson 7 4 ... 11
Brittany 3 14 ... 17
I would want the calculation to display Brittany, as she has the highest total.
Use INDEX/MATCH:
=INDEX(A:A,MATCH(MAX(L:L),L:L,0))

Excel macro to find a date in a range and then count for next value change in an adjacent column

I am attempting to write a macro to find February 2nd of each year in column A and then count the number of rows (days) until the value in column B changes. This count could be put in a new column, column C, but on the same row as the February 2nd that it correlates to, in this case row 3.
Using the table below the output to C3 would be 5. I am not counting the day of February 2nd but I am counting the day the change occurs. This is for 100+ years that I will need to loop through.
id | A | B | C
----------------------------
1 | 1946/01/31 | 0 |
2 | 1946/02/01 | 0 |
3 | 1946/02/02 | 0 |
4 | 1946/02/03 | 0 |
5 | 1946/02/04 | 0 |
6 | 1946/02/05 | 0 |
7 | 1946/02/06 | 0 |
8 | 1946/02/07 | 2 |
9 | 1946/02/08 | 0 |
The real challenge is to do it with a formula. Well, 2 formulas.
The first formula in cell E2 finds the date 2nd Feb by looking for "02/02" at the end of the text in column B and if it is found it places the contents of C2 in that cell. if it's not found it compares C1 with D1, the 2 cells above to see if they are the same because a match was previously found and if so it takes the contents of the cell above. This results in the zeros you can see in column E between 2nd Feb and the point where column C changes.
Formula for E2 and then autofill down to the end of your data
=IF(AND(MONTH(B2)=2,DAY(B2)=2),C1,IF(AND(E1<>"",E1=C1),E1,""))
Now all we need to do is count the cells in column D by looking for the first non blank cell in column D AND(E1="",E2<>"") and then count all the cells that match that cell. I'm not sure what gap you're expecting to find but you can change the 200 to ensure that you count everything. The last part is to take away 1 so that the 2nd feb row is not being counted.
Formula for D2 and then autofill down to the end of your data
=if(AND(E1="",E2<>""),countif(E2:E200,E2)-1,"")

duplicate for every block

I have this Excel table example:
A B C D
--------------
1 | 1 a 1 x
2 | b 1
3 | c 2
4 | a 3 x
5 | 2 r 4 x
6 | r 4 x
7 | t 1
8 | 4
9 | 3 a 1
10| b 3 x
11| c 3
12| b 6 x
I need to find duplicates (marked with x in column D) for every each block, but only in the context of it's own block (a block is what is found between A1 and A4 - for 1, another block is from A5 to A8 - for 2, and so on). B1=a it's not a duplicate for B9=a, because B9 belongs to block 3 and B1 belongs to block 1. But B1 is a duplicate for B4, they are on the same block, therefore both B1 and B4 should be marked with x.
I'm struggle with dynamic range finding/composition:
Basically I need in column D to find the range (starting with position in D first not empty field in A up, and first not empty field in A down). Eg: in D4 I need to get first non empty in A is A1, and first non empty in A is A5, and construct the range as A1:A5-1.
Use a helper column to avoid the need of an array formula:
In d2 put:
=IF(A2="",D1,A2)
Which will fill in the missing column A values:
Then in E2:
=IF(COUNTIFS(D:D,D2,B:B,B2)>1,"x","")
If you want the array formula:
=IF(COUNTIF(INDEX(B:B,AGGREGATE(14,6,ROW($A$1:INDEX(A:A,ROW()))/($A$1:INDEX(A:A,ROW())<>""),1)):INDEX(B:B,IFERROR(AGGREGATE(15,6,ROW(INDEX(A:A,ROW()+1):INDEX(A:A,MATCH("zzz",B:B)))/(INDEX(A:A,ROW()+1):INDEX(A:A,MATCH("zzz",B:B))<>""),1)-1,MATCH("zzz",B:B))),B2)>1,"x","")

How to multiply the reverse of a column with another column in excel?

Suppose i need to multiply the entries in these two columns in the following order in MS Excel
This is just an example
A | B
1 | 5
2 | 10
3 | 15
4 | 20
bolck1:1*5
block2:(2*5)+(1*10)
block3:(3*5)+(2*10)+(1*15)
block4:(4*5)+(3*10)+(2*15)+(1*20)
how would i do it?
I used SUMPRODUCT(A4:A1,B4:B1) but it returned the same old sum 150 as was the case with SUMPRODUCT(A4:A4,B1:B4).
You could add a helper column. In C1 put:
=SUMPRODUCT(A1*INDEX($B$1:$B$4,1):INDEX($B$1:$B$4,COUNT($B$1:$B$4)-(ROW(1:1)-1)))
Drag it down then total the results:

excel, combine multiple columns into one row

Am new to this so any help would be greatly appreciated.
I have an excel spread sheet with multiple columns, and I want to combine several columns into one column but maintain the same row. i.e.
from:
Name Address Phone1 Phone2 Phone3
Joe box 5 123-456-7890 Null 312-778-2564
Sue 3 w 2nd ST. 345-789-3214 156-879-5461 278-444-5687
Mike box 12 Null 666-879-4518 777-548-9851
To:
name address Phone
Joe box 5 123-456-7890
Null
312-778-2564
Sue 3 w 2nd ST. 345-789-3214
156-879-5461
278-444-5687
Mike box 12 Null
666-879-4518
777-548-9851
Say your information is in columns A and B so:
A | B
1 | z
2 | y
3 | x
To combine A and B in column C you would write the following in cell C1 and copy it down
=A1&B1
The final result would be
A | B | C
1 | z | 1z
2 | y | 2y
3 | x | 3x

Resources