Index formula issue - excel

Can you please help with the above? Basically, i am trying to automate a list of names based on another persons name within an organization. I.e. John Smith being a manager, I want to return every person who is under John Smith. So, my formula is as below:
=IFERROR(INDEX(Sheet1!B:B,SMALL(IF(Sheet1!A:A=$AF$34,ROW(Sheet1!B:B)-MIN(ROW(Sheet1!B:B))+1),COLUMNS($AF$34:AF34))),"")
Sheet1!B:B is where the employees are and Sheet1!A:A is where the managers are. When i press control shift and enter, that works and returns the correct value. The problem is however, say I have 10 people under John Smith and the next manager is Dave T, the list will carry on and auto populate people under Dave when i want it to return the "" value provided in the IFERROR (presuming they are not under John Smith). To do this, i am adding +1 to:
...(Sheet1!B:B))+1),COLUMNS...
i.e.
...(Sheet1!B:B))+2),COLUMNS... ...(Sheet1!B:B))+3),COLUMNS...
This is driving me insane, can you please help?
Thanks, Colin.

Firstly, if at all possible it is best to avoid using entire columns for INDEX formulas for performance reasons, but if this is your only formula you should be fine.
Now as you are indexing the entire column, you shouldn't need to offset the row result (and in my example i start the index from row 1 so again no need to offset). In addition, you want to have the small update one step at a time, this is most commonly done with ROW(1:1) [Vertical dragging] or COLUMN(A:A) [horizontal dragging] your method also works but people are lazy and like to save characters:
=IFERROR(INDEX(Sheet1!B:B,SMALL(IF(Sheet1!A:A=$AF$34,ROW(Sheet1!B:B)
-MIN(ROW(Sheet1!B:B))+1),COLUMNS($AF$34:AF34))),"")
Essentially your formula will work for dragging horizontally but not for vertical dragging, it will always yield the first row number in the array...
=IFERROR(INDEX($B$1:$B$11,SMALL(IF($A$1:$A$11=$AF$34,ROW($B$1:$B$11)),ROW(1:1))),"")
Ctrl + Shift + Enter (formula bar)

Say we have:
In D2 enter the mane of the manager of interest. In C2 enter:
=IF($D$2=A2,1+MAX($C$1:C1),"")
and copy down:
The Helper column marks each subordinate with a unique seq. number.
Finally, in E2 enter:
=IFERROR(INDEX(B:B,MATCH(ROWS($1:1),C:C,0)),"")
and copy down:
NOTE:
By changing a single cell, D2, we can pick a different manager.

Related

Moving two MS Excel cells that depend on each other

I have a table where I enter the qualification times manually Name and Timer. It calulates the Final Time automatically, but I want it to sort the Final Time and Name in the right side from the fastest to the slowest, as in the second image. I tried using VLOOKUP and INDEX, but didn't manage to get it. I need help finding the right formulas to Cells I$ and J$. I hope to get a answer from here.
Hope to get it like following:
Use this formula in your column J. Enter it in J3 and copy down. As you see, it refers to column H where it expects the numbers 1 and up. So, it will look for the smallest, second smallest etc values in the given range.
=SMALL($D$3:$D$6,H3)
In I3 please enter the formula below and copy down.
=INDEX($B$3:$B$6,MATCH(J3,$D$3:$D$6,0))
It looks for the value the SMALL function extracted and finds the matching name.

Excel counts the number of times a value appears in a group of columns but counts only one instance of the name per row

I need to find the number of times a name appears on this list but I only want to count one instance of the name one time for each row without counting the duplicate name in the row.
For instance: I have the following in a range...
Red Bill Jack Ruby Bill
Blue Ruby Ivan Raul Ted
Green Ted James Rick Ted
Red Ted Phil Ruby Bill
And in this worksheet, I want to count the number of instances of the name Bill and get the answer of 2 because Bill's name shows up in two rows. In the same respect, If I choose to count the name Ted, the answer should be 3 because Ted's name shows up in three rows.
Use OFFSET with SUMPRODUCT. In F7 (per supplied image) as,
=SUMPRODUCT(SIGN(COUNTIF(OFFSET(B$1:E$1, ROW($1:$4)-1, 0), E7)))
The SIGN function turns any positive number to 1 for each row. ROW(1:4) cycles through each of the rows.
Assuming you put your name of choice, e.g. "Ted", in G1, array formula**:
=SUM(0+(MMULT(0+(A1:E4=G1),TRANSPOSE(COLUMN(A1:E4)))>0))
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).
A non-vba solution with a helper column in column F.
Column F formula =IF(COUNTIF(B1:E1,$I$1)>0,1,0)
J2 formula =SUM(F1:F4)
change I1 as needed for name.

How to get the five highest values from a list in Excel

In my sheet I have a Column1 with text and a Column2 with random numbers.
I would like to get a Column3 with the five "highest texts" for example:
I know I can get the text if I make an Index/Match looking for the number, but I'm lost at the sorting part.
Place this in cell C1 and drag down:
=LOOKUP(REPT("z",255),IF(LARGE($B$1:$B$10-(ROW($B$1:$B$10)/9^9),ROWS($A$1:A1))=$B$1:$B$10-(ROW($B$1:$B$10)/9^9),$A$1:$A$10))
This needs to be entered with CTRL + SHIFT + ENTER.
Use a 'helper column' to get the top 5 numbers with the LARGE function then use INDEX on column A, returning the appropriate row number with AGGREGATE and COUNTIF function to offset duplicates.
        
additional variant to already posted:
=INDIRECT("A"&MATCH(LARGE(B:B,ROW(A1)),B:B,0))
test:
The question is: What if there is not a clean break between 5th and 5th place? For example what if f was also a 6? This would then be tied for with the others how does one descriminate?
The following will bring out only the 1st through the 5th but allow for ties that might push the actual number past 5 due to ties.
Put the following in C2:
=IF(OR(ROW(1:1)<=5,COUNTIF($C$1:$C1,INDEX($A$1:$A$10,MATCH(LARGE($B$1:$B$10,ROW(1:1)),$B$1:$B$10,0)))>0),INDEX($A$1:$A$10,MATCH(1,INDEX(($B$1:$B$10=LARGE($B$1:$B$10,ROW(1:1)))*(COUNTIF($C$1:$C1,$A$1:$A$10)=0),),0)),"")
It is an array formula and must be confirmed with Ctrl-Shift-Enter. Then copy it down ten rows(in the picture the formula is copied down ten rows).
Now we change f to be 6 so it is tied for fifth:
And it gets added to the list.
You could just limit the output to five rows. But then it would be excel deciding what is the top five. If this is what you want than any of the other answers will work.

Using the 'Match' function in Excel to return a cell address

I have a list of numbers in a table that I would like to search for and bring back the cell reference of where that number resides. For example the data looks like:
A B C D
1 1 2 3 4
ok it doesn't come out very well as the first one is the row number and then each number below sits under each letter, so C1 would contain '3'....
If I wanted to return the reference number of C1 in a cell I am using the formula of =CELL("address",MATCH(AU14,C1:AG1)) but this just errors. I have tried to put an Index in there too, but I believe that index only works vertically so this bring back a #N/A result.
Can anyone assist as I've wasted too much time on this already! :)
You are indeed missing an INDEX. And INDEX works vertically, horizontally, or both depending on how it's called.
Here is a formula that works for the ranges in the pictures. Should be easy to modify.
Formula in C5
=CELL("address",INDEX(B2:F2,MATCH(C4,B2:F2,0)))
formula
results
To make CELL work you need a cell reference, e.g.
CELL("address",C1)
The trouble is that MATCH just gives you a number, not a cell reference.
Probably the easiest way is to use the ADDRESS function, so a first try might be
=ADDRESS(1,MATCH(AU14,C1:AG1,0)+2)
That would give you the right answer if AU14 contained 3, but isn't considered to be very good because it wouldn't update if you deleted/inserted rows or columns.
A better one would be
=ADDRESS(ROW(C1),MATCH(AU14,C1:AG1,0)+COLUMN(C1)-1)
Then you might want to put in some error handling for the case where it's not found
=IFERROR(ADDRESS(ROW(C1),MATCH(AU14,C1:AG1,0)+COLUMN(C1)-1),"Not found")

How to get the newest value from a column with conditions

I have a table in Excel which has the columns:
Date
Person Name
Amount (£)
The table is used to record when people pay me money. Typically, I can get more than one person paying me on the same day. Also, the same person will pay me on many days over the course of time.
Records are added to the bottom of the table so the ordering will be on date but no further ordering on name or amount.
Using formulas, is there a way I can retrieve the most recent amount for a specific person?
If this is too complicated or not possible then I can settle for the following work around:
Add a 4th column to the table called "Last". This will display TRUE if it is the last entry for a specific person, FALSE if it is not.
It felt like there should be a fairly straight-forward answer to this but I found it quite a head scratcher so was interested to see an answer.
Having done some googling I came across a solution posted on a dedicated excel site (view here). [NB - look under the header 'Arbitrary Lookups']
Applying it to your example, suppose your data is in A1:C10 and in cell D2 you want to type a name and return the most recent payment in cell D3:
1 Date Name Amt EnterName
2 20 Jul Bob 50 <enter name here>
3 13 Sep Susan 20 = enter formula here (see below)
4 06 Jan Xavier 100
In cell D3 enter the following as an array formula (i.e. type in formula and then press CTRL + SHIFT + ENTER
=INDEX($B$2:$C$10,SMALL(IF(OFFSET($B$2:$C$10,0,0,ROWS($B$2:$C$10),1)=$D$2, ROW(OFFSET($B$2:$C$10,0,0,ROWS($B$2:$C$10),1))-ROW(OFFSET($B$2:$C$10,0,0,1,1) )+1, ROW(OFFSET($B$2:$C$10,ROWS($B$2:$C$10)-1,0,1,1))+1),COUNTIF(OFFSET($B$2:$C$10,0,0,ROWS($B$2:$C$10),1),$D$2)),2)
It would recommend checking out the link I provided if you want more detail. For clarity, I have merely adapted the formula (changed cell references) from the link provided.
Here's one way to do it based on an answer I gave in a previous SO post.
=INDEX($C$1:$C$19,MATCH(MAX(IF($B$1:$B$19="PersonNameHere",$A$1:$A$19,0)),IF($B$1:$B$19="PersonNameHere",$A$1:$A$19,"")))
Where A is the Date column, B is the Person Name column, and C is the Amount column. You must enter this as an array formula by pressing Ctrl+Shift+Enter.
I can't see right here an easy way to do it in only one formula.
If you have your data from A2 to C11.
You can add this formula on the 4th column (let say in cell D2):
{=MAX(IF($B$2:$B$11=B2,$A$2:$A$11,0))}
This is an array formula you have to validate with Ctrl-Shift-Enter
This will tell you what is the last date for the current person.
And then find the last amount with another column (let say in cell E2) and use this formula:
=INDEX($C$2:$C$11,MATCH(D2,$A$2:$A$11,0))
[EDIT] I've just tried to combine the formulas into one and that simply works:
{=INDEX($C$2:$C$11,MATCH(MAX(IF($B$2:$B$11=B2,$A$2:$A$11,0)),$A$2:$A$11,0))}
and this is still an array formula.
Alas, #Excellll was smarter (and faster) and gave the solution at first shot

Resources