Find Largest Value in one cell and then display a different cell in the same row - excel

This was a fairly difficult question to put to words but hopefully the example data and my attempt will help
I have the following
Apple 17 1 0 0 0 0 0 0 0 0 0 0
Orange 14 1 15 1 6.67 1 6.67 1 6.67 2 13.33 10
Banana 15 3 5 0 0 0 0 0 0 0 0 1
Cherry 13 1 12 2 16.67 2 16.67 2 16.67 2 16.67 2
Peach 16 4 12 1 8.33 1 8.33 2 16.67 2 16.67 8
Strawberry 12 5 6 1 16.67 1 16.67 1 16.67 1 16.67 7
I am trying to find the max value in M and then display A from the same row. So in this example the max value would be 10 and "Orange" should be displayed.
It should be noted that I am using 2 sheets, "Data" has my output and "Raw Data" has... the raw data
=VLOOKUP(MAX('Raw Data'!M1:M6), A1:M6, 1, FALSE)
This produces #N/A and I think it might have something to do with my data either not being formatted into a table (though doing so seems to fail with a different error) or running from one sheet to the other.
Any input would be greatly appreciated

VLOOKUP requires that the value to find is in the first column.
Use INDEX/MATCH:
=INDEX(A1:A6,MATCH(MAX(M1:M6),M1:M6,0))

Try this =INDIRECT(ADDRESS(MATCH(MAX(M1:M6),M1:M6,0),1))

I recomend using Index Match as Scott Craner has shown.
But if you are set on using vlookup:
I will first shortly explain vlookup as how I have understood it.
First a limitation, vlookup can only return values to the left of your search range, i.e you cant use negative numbers i.e,
=vlookup(Max('Raw Data'!M1:M6), A1:M6, **"-1"**, False)
Secondly, vlookup is structured like this:
=vlookup(The value you want to search for, the range you want to work with, which column you want to return a value from (1 means the first column).
vlookup will allways search for the vale you want to search for in the first column.
So in your data:
You are telling vlookup to search for the maximum value that exists in the range M1:M6. In this case 10 right?
You are telling vlookup to search for this value in column A which contains the fruits. This is where it goes wrong.
My solution to this would be to move all the fruits names to the N column (to the left of you values you want to search).
In code:
In the N Column:
Put = A and the row number
Now do a vlookup like this:
=vlookup(Max('Raw Data'!M1:M6), M1:N6, 2, False)
I hope this can solve your problem.
Best regards,

Related

Finding maximum value in group

I want to create a column of data that finds the largest value in column BD, based on individual values in Column B. I would have thought this equation would work! Anyone have any recommendations??
(first attempt)
=IF(BD3=0,0,SUMIFS($BD$3:$BD3,$B$3:$B3,B3,$BD$3:$BD3,MAX($BD$3:$BD3)))
(Second attempt)
=IF(BD3=MAXIFS($BD$3:$BD3,$B$3:$B3,B3),MAXIFS($BD$3:$BD3,$B$3:$B3,B3),0)
Projectid(B)
cumulative production(BD)
result I want()
1
20
0
1
60
0
1
70
70
2
0
0
2
0
0
3
20
20
4
0
0
5
0
0
6
0
0
7
10
0
7
40
0
7
60
60
this code should work:
=IF(MAXIFS($BD$1:$BD$12,$B$1:$B$12,A1)=BD1,MAXIFS($BD$1:$BD$12,$B$1:$B$12,B1),0)
If you have access to LAMBDA() function then can use below formula at one go.
=LET(a,BYROW(A2:A13,LAMBDA(x,MAXIFS(B2:B13,A2:A13,x))),IF(B2:B13=a,a,0))
Similar to SUMIFS you find MAXIFS
https://support.microsoft.com/en-us/office/maxifs-function-dfd611e6-da2c-488a-919b-9b6376b28883
Then just compare the MAX with the actual row value.
Edit based on your reply:
One way is to start with one operation in the cell first then it is easier to follow.
Your MAXIF should be like this (looking for the max in column B of those rows having the same value in column A as the value of current column A)
=MAXIFS(B$2:B$13;A$2:A$13;A2)
Then compare to B2
So, basically you got it, need just to adjust your second part of the MAXIFS :-)

Formula to put 1 in the first value and 0 for the rest. Duplicate dataset

I'm looking for a smart way to indicate only one row with duplicated values. I need it to help my pivot table a little.
Id Description Estimation(h) Formula
1 Desc1 20 1
1 Desc2 20 0
1 Desc3 20 0
2 Desc4 30 1
2 Desc5 30 0
2 Desc6 30 0
This looks quite simple: I just put the value 1 as the first value, and the rest of the column is based on the following formula:
=IF(A2=A3;0;1)
(I've put this formula in cell D3)
This option will work even if the Id is not sorted:
=--(COUNTIF($A$2:A2,A2)=1)

Excel using SUMIF to calculate totals of multiple columns

I'm trying to use Excle's SUMIF to calculate totals of Col1 to Col5 for dates that are similar.
My formula is as follows =SUMIF($A2:$A7,A10,$B2:$F7), but this only gives me the total of a single column.
How can I get the Totals of all the columns based on the date like I've shown in my results.
Date Col 1 Col 2 Col 3 Col 4 Col 5
1/5/2017 1 2 2
1/5/2017 5 3 1
1/5/2017 9 5 5
2/5/2017 10 5 3
2/5/2017 20 10 3
2/5/2017 6 8 1 5
Desired Results
1/5/2017 15 7 7 3 1
2/5/2017 30 11 11 11 8
use below formula in cell B11
=SUMIF($A$2:$A$7,$A11,B$2:B$7)
Per the example you provided, One solution is to use SUMPRODUCT
Multiplies corresponding components in the given arrays, and returns the sum of those products
Microsoft Docs give a thorough example, but per SO etiquette, here is an example in case of link-rot: [FYI, I used absolute reference for easier filling across, arbitrary how you get it done though]
Forumlas shown:
Formula is kind of hard to see without clicking on image:
=SUMPRODUCT(($B$3:$B$8=$B$11)*C3:C8)
This basically breaks down like this, it searches the B:B column for a match, and it will naturally return a true or false for the match, or 0/1 counterparts, and multiplys that by the number found in the column to the right (C3:C8), so it will either be 1 * # = # or 0 * # = 0

Indexing questions with array formulas in Excel

I'm new to array formulas in Excel and my brain has been trained in R for too long, so I'm sorry if this question is simple or too specific. I have data that looks like this:
ID Iteration Value Group1 Group2
2 1 100 0 0
2 2 85 1 0
2 3 28 0 0
3 1 94 1 0
5 1 83 0 1
5 2 50 1 1
6 1 94 0 0
6 2 28 1 0
I want to use array formulas to query the data in a few different ways. I want to:
For each ID, find the first iteration that has Group1 = 1.
For each ID, what is the maximum value when Group1 = 1.
For each ID, how many iterations of Group1 = 1 did it take to get to the maximum value when Group1 = 1.
I've figured out how to specify the maximum for each ID via: {=MAX(IF(A:A=A2,C:C))}
Any assistance would be appreciated. I've gone through a few quick tutorials so far, and I'm willing to look through any other good resources you may know of.
Have a look at this and tell me what you think - particularly for question 3
My setup looks like this
All formulas drag down and they are as follows:
Formula in B14 (Question 1)
{=INDEX($B$2:$B$9,MATCH(1,($A$2:$A$9=A14)*($D$2:$D$9=1),0))}
Formula in G14 (Question 2)
{=MAX(($A$2:$A$9=$F14)*($D$2:$D$9=1)*$C$2:$C$9)}
Formula in K14 (Question 3)
{=SUM(($A$2:$A$9=J14)*($C$2:$C$9=G14)*$B$2:$B$9)}
Update
If you want to know how many times in ID=2 that Group1=1 before we reach the maximum we found for ID =2 in question 2, then I'd proceed like this:
Add another column to your data, I labeled it: Group1 Passes. Placing this in the new column, F2, and drag down.
=COUNTIFS($A$2:A2,A2,$D$2:D2,1)
You can then use the following in K14
=SUM(($A$2:$A$9=J14)*($C$2:$C$9=G14)*($D$2:$D$9=1)*$F$2:$F$9)

Finding the first ocurrence of a string below a given cell?

I've been trying to figure this out but I don't seem to get it right.
I have a spreadsheet with reports for different categories detailed by day (e.g. Toys, Drinks, General Store, Meat Store, Veggies, etc)
So, my spreadsheet looks something like this:
Toys
Day Me Wife Kid1 Kid2
9/28/13 0 0 0 0
10/1/13 29 3 0 0
10/2/13 0 7 34 25
10/4/13 0 0 0 0
AVERAGE 29 5 34 25
.
Drinks
Day Me Wife Kid1 Kid2
9/30/13 102 15 0 0
10/1/13 0 0 25 0
AVERAGE 102 20 0 0
etc etc
So the idea would be that I need to be able to find the Average row number for each different category, but I can't just look for it easily because in one category there might be expenses on more months (hence, more rows between the category's title and the average row). Any clues?
You can use
=ROW()+MATCH("AVERAGE",$A2:$A$1001,0)-1
The row reference to A2 is variable and you can paste it next to the category of interest. The row reference to A1001 is just far enough down in your spreadsheet to include all the data, and is fixed (but doesn't have to be).
You can use something like this perhaps:
=MATCH("AVERAGE",INDIRECT("A"&MATCH("Drinks",A:A,0)&":A1000"),0)+MATCH("Drinks",A:A,0)-1
MATCH("Drinks",A:A,0) returns the row number of Drinks
Which is used by INDIRECT and to convert into a range, from which MATCH then returns the number of rows after that header. Add to the number of rows before Drinks and remove 1 to get the actual row number.
Change the range of A1000 accordingly. I assumed a maximum of 1000 rows here.
Edit, if you have cross-sheet referencing, you need to change the formula to:
=MATCH("AVERAGE",INDIRECT("'Sheetname'!A"&MATCH("Drinks",'Sheetname'!A:A,0)&":A1000"),0)+MATCH("Drinks",'Sheetname'!A:A,0)-1
Assuming Sheetname is the name of that sheet.

Resources