Displaying the contents of a cell based on the max fuction - excel-formula

I am running a MAX function of a row of data such as:
+------+-----+------+------+-------+------+------+--------+------+------+--------+------+
| John | Doe | 4323 | Eric | Smith | 1235 | Sean | Wilson | 4567 | Jeff | French | 3212 |
+------+-----+------+------+-------+------+------+--------+------+------+--------+------+
(with each item being in a different cell)
Naturally the MAX function running on this whole row will return the 4567. I would like the cell in front of the MAX result to return the first name that directly proceeds the result such as:
Sean 4567
Keep in mind that the first name, last name and the number are in separate columns but on the same row, but always located in a cell a constant number of cells before the result. (I don't need nor want the last name for this result)

Suppose you have your values at row 4, from Column D to O.
The following will get you the name (Sean) instead of the MAX value (4567):
=INDEX(D4:O4,MATCH(MAX(D4:O4),D4:O4,0)-2)
The MATCH formula will return position 9, the INDEX formula will return the value at position 9. We want to return position 7, so subtract 2 and the INDEX will return "correct" result. The -2 is how many positions the return values should be offset (2 cells before the actually MAX value is found).
If you want Sean 4567 I should combine the the two formulas:
=INDEX(D4:O4,MATCH(MAX(D4:O4),D4:O4;0)-2) &" "& INDEX(D4:O4,MATCH(MAX(D4:O4),D4:O4,0))
Or
=INDEX(D4:O4,MATCH(MAX(D4:O4),D4:O4,0)-2) &" "& MAX(D4:O4)
You already mention it, it only works if the offset is constant across the row (Name is always located 2 cells before value cell).

Similar to what Wizhi said, but slightly shorter. Assuming the info is on row 1:
=INDIRECT(ADDRESS(1;MATCH(MAX(1:1);1:1) - 2))
Where your row number number is given (1:1), col number finds the max and goes 2 before (the given offset), and INDIRECT(ADDRESS()) concatenates it with the row number and finds the name there ('Sean', in this case.)

Related

How to use VLOOKUP function for a column which value is generated from another two column

I want to populate this formulae but this level of nested loop are not allowed...
=IF(D2<101,"27.50",IF(D2<151,"21.34",IF(D2<201,"26.07",IF(D2<251,"29.81",IF(D2<301,"34.54",IF(D2<351,"39.27",IF(D2<401,"44.00",IF(D2<451,"49.72",IF(D2<501,"56.87",IF(D2<551,"61.60",IF(D2<601,"66.33",IF(D2<651,"71.06",IF(D2<701,"75.90",IF(D2<751,"80.63",IF(D2<801,"85.36",IF(D2<851,"87.67",IF(D2<901,"90.97",IF(D2<951,"92.40","97.90"))))))))))))))))))
where D2 is calculated like =(A2+B2)/2
You can use INDEX(MATCH()) to solve your issue, but the order of lookup array must be descending, and your limits should be +1 as it works in greater than or equal to form, so if this is the lookup table:
A B
252 29.81
202 26.07
152 21.34
102 27.5
This will be the formula:
=INDEX($B$1:$B$4,MATCH(D2,$A$1:$A$4,-1))
The best way to go about this is to use a lookup table as a half-way point, either somewhere on the sheet or in hidden cells/sheet if preferred.
The table will look something like this:
|-----|-------|
| 101 | 27.5 |
|-----|-------|
| 151 | 21.34 |
|-----|-------|
| 201 | 26.07 |
|-----|-------|
etc...
Then you can use a lookup to find the value based on the condition, let's say this table is in Sheet2!A1:B3:
=IFERROR(INDEX(Sheet2!$B$1:$B$3,SMALL(IF($D$2<Sheet2!$A$1:$A$3,ROW(Sheet2!$A$1:$A$3)-ROW(Sheet2!$A$1)+1),1)),"97.90") - Entered as an array formula (Ctrl+Shift+Enter)
INDEX(Sheet2!$B$1:$B$3, - Create a 1 based index (index starting from 1) of B1:B3
IF($D$2<Sheet2!$A$1:$A$3,ROW(Sheet2!$A$1:$A$3)-ROW(Sheet2!$A$1)+1 - Returns a reference to the position of the all items in A1:A3 that are larger than D2 as an array (by taking the row number minus the row number of the first row plus 1)
SMALL([If()],1) - Return the first, smallest row number from the array that INDEX() then looks for
IFERROR([Index(Small(If()))],"97.90") - As any number greater than the largest number in the table will produce an error, then return "97.90" instead

Finding % based on multiple cells and using MATCH formula

Trying to come up with a formula for a spreadsheet I am working on, but hit a road block.
I need to use an INDEX and MATCH formula to ensure that the cell is going to lookup a sheet full of data and find all matches based on an ID number. I then need to work out the % value of how often that column was populated with data for that ID number.
Essentially as an example:
The data table would look like:
ID | Notes Added
1 | Yes
7 | Yes
12 | Yes
6 | Yes
10 |
12 |
And the result would be:
ID | Populated %
12 | 50 %
As you can see, the values that it should return would be 50%, as there are 2 entries that are listed for the ID of 12 (this is where the MATCH and INDEX would come in), however in the Notes Added, only 1 of the entries has a value.
The data table that it draws from will either have a value, or have no value, calculating the % would be based on if there is/isn't a value.
You'll want to use COUNTIFS Function. It would look something like this:
=COUNTIFS(B4:B9,C16,C4:C9,"Yes") / COUNTIF(B4:B9,C16)
=COUNTIFS(<ID Values Range>,<Id Value>,<notes added range>,"Yes") / COUNTIF(<ID Values Range>,<Id Value>)
Then just set the cell formatting to %.

Compare two excel columns which the most frequently occur in specific date

I would like to compare between few columns, what where the top 5 most popular products in year 2015.
I have this kind of data flow to work with:
Client | Product | Date of buy
------------------------------
client1 | A | 15.06.2015
client3 | A | 04.12.2015
client5 | F | 15.06.2015
client9 | G | 15.01.2015
client2 | G | 15.01.2015
client1 | R | 05.07.2015
client3 | G | 15.06.2015
client1 | F | 05.07.2015
client3 | F | 15.06.2016
Results - which products client bought the most with (in same date) the top 5 products communities of them. E.g..
1. Product A + Product H 222 times
2. Product A + Product E 77 times
3. Product B + Product O 70 times
4. etc
5. ...
Greetz,
Making the assumption:
you can use helper columns.
Your Columns up above are A, B and C.
You have two header rows and data starts in row 3.
Your dates are stored in an excel date format and not string values.
In E2 I generated a list of unique product items using the following formula:
=INDEX($B$3:$B$11,MATCH(0,INDEX(COUNTIF($E$2:E2,$B$3:$B$11),0,0),0))
I copied it down to match the number of rows in the initial list. It starts spitting #N/A when all the unique items in the list have been listed. If you want to avoid this you could put the formula inside of:
=IFERROR(insert formula,"")
Now in column F I did a count based on your criteria of each item and within the year 2015. I used a multiple count if function called COUNTIFS:
=COUNTIFS($C$3:$C$11,"<"&DATE(2016,1,1),
$C$3:$C$11,">"&DATE(2014,12,31),
$B$3:$B$11,E3)
I just reformatted that for easier reading. You will have to edit that slightly if you want to copy and paste. If you don't like seeing 0 when there is no product in the adjacent column you could wrap the equation in:
=IF(E3="","", insert formula )
I then skipped a column and sorted the list of counted items from largest to smallest and had it return the numbers in sequence. I only went down two rows, but you could technically do the whole list. The large function does this and the formula in H3 looks like:
=LARGE($F$3:$F$11,ROWS($1:1))
I then went back 1 column and put the product name that corresponds to the count, and then took the next name in the list when products had equal count. I put that in column F as normally when I read I want to read the product name first then read the quantity. If you want it the other way around just swap the columns. The formula in G1 is:
=INDEX($E$3:$E$11,MATCH(H3,$F$3:$F$11,0)+COUNTIF($H$3:$H3,H3)-1)
Copy E3 and F3 down as far as you need. Copy G3 and H3 down one row and you will have top two. down two rows and you have top three etc.
This is how it looks...The dates are displayed according to my computers date format.

How to find parent in an indented hierarchy?

I currently have a sheet in excel with an indented hierarchy of items as shown below. Each item is indented (four spaces per indent) to show how it fits into the overall hierarchy. I have been able to create a "Level" column that translates the indentation level into a number.
+------------+-------+--------+
| Item | Level | Parent |
+------------+-------+--------+
| P1 | 1 | N/A |
| P2 | 2 | P1 |
| P3 | 2 | P1 |
| P4 | 3 | P3 |
| P5 | 2 | P1 |
| P6 | 3 | P5 |
+------------+-------+--------+
What I want to do is generate the "Parent" column above, which uses the "level" information to display each item's parent.I think that this would need to be done with a loop that would do this for each item X :
-Find level info for X
-Find (levelx-1) which would equal the parent item's level
-Search upward for the first row with a level equal to (levelx-1)
-Find the item number in that row
-Write item number in adjacent cell to X
Unfortunately, I'm not sure how to translate this idea into VBA.Thanks in advance for any assistance.
OK, assuming the above table starts in cell A1, useful data starts in row 2. This formula will do the trick:
=INDEX($A$1:$A$7,MAX(IF($B$2:$B2=B2-1,ROW($B$2:$B2),"")))
Enter this in cell C2 as an array formula (Ctrl+Shift+Enter), then pull it down. The first one will obviously be an error (not #NA but #VALUE).
How it works:
IF($B$2:$B2=B2-1,ROW($B$2:$B2),"")
This creates an array with the row numbers for values with one level lower than the actual value. To examine only the values above the current row, you need to use expanding ranges, hence the $B$2:$B2 style references.
The MAX function gets the maximum of these rows, which is the closest to our current cell. Now we have the row number. All we need now is a formula to extract the data from column A from the indicated row. This is what INDEX does.
It took me a while to understand how this formula works, so after figuring it out (ok, my wife helped me a bit) I'd like to share an idiot-proof explanations for other Excel-dummies like me. Here we go:
=INDEX($A$1:$A$7,MAX(IF($B$2:$B2=B2-1,ROW($B$2:$B2),"")))
means:
Among values in range $B$2:$B2 find all values that equal to
B2-1.
If you find them, list the row numbers with value equal to
B2-1. (ROW)
From the list of the row numbers, pick the highest
row number (lets call it number X). (MAX)
Return the value which is in the line number X in the range $A$1:$A$7
(Warning! Your range has to start in the row no. 1, so that the row number is the same as the line number in your range. Otherwise - you have to adapt the formula.)

using SMALL function to retrieve lowest value in range, trying to combine with OFFSET to get value to the left

I am using the SMALL formula in H2 to find the lowest price in the row, which works great.
=IF(ISERROR(SMALL(A2:F2,COUNTIF(A2:F2,0)+1)),"",SMALL(A2:F2,COUNTIF(A2:F2,0)+1))
I am having trouble retrieving the value to the left of it (its corresponding item#) with OFFSET.
A | B | C | D | E | F | G | H
item# | price | item# | price | item# | price | lowest value item# | lowest value
123 | 70 | 456 | 80 | 789 | 67.89 | ? | 67.89
Also,I do not know which column will have the lowest value, A-F can change.
I've spent several hours searching and tried using the original formula as the Reference part for the OFFSET:
=OFFSET(IF(ISERROR(SMALL(A2:F2,COUNTIF(A2:F2,0)+1)),"",SMALL(A2:F2,COUNTIF(A2:F2,0)+1)),0,-1,1,1) and variations of it. This returns #Value!
Am I on the right track? Is OFFSET the correct way to do this? Thanks
I would also remove the dependency on H2 by replacing it thus, simply adding a MIN function
=INDEX(A2:F2;MATCH(MIN(A2:F2);A2:F2;0)-1)
however, you always need to distinguish between item number and price. Sometimes the item value could be lower than price and then your formula wouldn't work. It would return the item value as the lowest value and then will return the price for the preceding item. It would be a mess.
So to resolve this, you need to add two MATCH conditions to look for the exact match:
here is the formula the LOWEST VALUE ITEM#:
=INDEX(A2:F2;(MATCH(MIN(IF(A1:F1="Price";A2:F2));A2:F2;0)-1)*(MATCH("Item#";A1:F1;0)))
and the formula to find the LOEWST VALUE PRICE
=MIN(IF(A1:F1="Price";A2:F2))
For example in the following:
Value in C2 is the lowest, however it is not the lowest price value, which is itself in F2 That is why you need to add these match conditions to find the value above which is item# or above which is Price.
So for Price I used MIN(IF and for Item# i used a MATCH condition.
here is the excel sheet example downloadable from dropbox
P.S. do NOT forget to adjust the formuals to your regional settings, by replacing the ";" with ","
tell me if it works.
Is OFFSET the correct way to do this? - No
OFFSET expects as its first parameter a range reference, not a value.
If your prices are unique, use this (if they are not, I'm not sure what result you would expect)
=INDEX(A2:F2,MATCH(H2,A2:F2,0)-1)
That said, your SMALL formula looks suspect. It looks like you want to return "" if all the prices are 0. But your formula will return the smallest item# in that case. Can you confirm or explain?

Resources