Get maximum value based on unique values - excel

I have two columns in Excel as follows:
col1 col2
1 10
1 22
1 11
1 23
1 14
2 16
2 12
2 10
2 9
How do I write a command to returns the maximum value from col2 corresponding to each unique value in col1?
So here I need to write a command to get 23 and 16.
The data I have shown here are dummies; I have 600 unique values in col1 in my actual data set.

Pivot tables: the single most underutilized and powerful feature of excel.
File menu:
Insert
Pivot Table
Select range
Fill in as indicated in image below
Step by Step:
Place cursor in cell to right of all data on sheet.
Select insert from menu
select pivot table icon
select pivot table from pop-up of icon
use the button to select the range of cells included (all 600+ rows in 2 columns) (or just enter $A:$B)
select ok
A pivot table field list appears on the right:
Drag and drop row 1 into row labels.
drag and drop row 2 into values area.
left click on "... of Row 2"
select value field settings
select "Max" instead of count or sum
select ok and you should have desired results.
The pivot table will find the max value in row 2 for each unique value in row 1 which is what I believe you are after.

Even if a solution has been found. I think it is too complicated and oversized to use the pivot for this and it might not be possible in all scenarios. Here is one that can be found searching the internet for "max if excel" (e.g. see here; adapted)
{=MAX(IF(A:A=A1,B:B))}
Attention! This is an array formula, you have to enter it without the curly brackets and then press Ctrl+Shift+Enter to submit the formula.

Since the left hand values seem to be in order, Subtotal should work.

Related

How to print top 3 employees in a region in excel?

I have a table with three columns, region, emp_name, salaries.
I want to add one more column to this table in excel.
That new column should have either 1 or 0. 1 indicates one of the top3 employee based on salaries in a particular region.
For example, Region1 has 7 employees, namely emp1, emp2, so on emp7. emp2, emp4, emp7 have top 3 salaries.
So in the new column, emp2, emp4, emp7 must have 1 and others have 0. Let's say this table contains n number of regions.
Put this in D2 and copy down:
=IF(C2>=AGGREGATE(14,7,$C$2:$C$1000/($A$2:$A$1000=A2),MIN(COUNTIF(A:A,A2),3)),1,0)
Use a pivot table
Insert the pivot using your whole range
Add Region/Employee to Rows field (In that order)
Add Salary (SUM) to the Values field
Below Pivot Table Design = No Subtotals, No Grandtotals, Tabular Layout
Select the drop down on Employee, Select Value Filter, Select Top 10...
Complete form with Top 3 Items by Sum of Salary
If a region does not have 3 options, the top n will appear where n < 3.
If you need to use the 1, 0 option you could just do a vlookup on this table too. Note that a error will return if they are not on this list which means they are not top 3. You can use some error handling to convert this to 1, 0

Fill in table based a column of categories in Excel

I have a table that looks like this:
Type Value
Movie 5
Food 3
Gas 10
Food 2
.... ....
And There's a second table I want to fill in with "Value" based on their type in the first table, so that the corresponding rows look like this:
Rent Food Movie Gas Clothing ... ( appear in specific order bc they are subcategories)
5
3
10
2
The title row is already there, so I was thinking there might be some kind of lookup method to do this? How do I do that?
your second table apperas to hold one value per row but it doesn't have a label. it does correlate to the original row number, is this by design or coincidence?
if this is by design then you can use those 2 columns, hide them if you like, get a unique list of categories by copying you r abels to a new colum, removing duplicates in the data tab, then paste special transpose in c1 to create colum headers.
so column a and b remain unchanged
row 1 contains header starting at column c
your data starts at c2
this is the formula
=Iferror(vlookup(C$1,$A2:$B2,2,false),"")
drag it down and to the right
you can copy paste special values when done to remove the formulas
for something with only a hundred or thousand cells this will be one of the easier options but i would not do this on large tables, for those i would use power query or VBA
Assuming your 1st table is in Sheet1 and 2nd table is in sheet2.. you may try to fill in Sheet2!A2
=IF(Sheet1!$A2=A$1,Sheet1!$B2,"")
and drag it all the way.. Hope you get how it works.. and what you need.

Excel - linked cells

I have one table in Sheet1 with next data
and second table in Sheet2 with simular data
As you can see in first table in first row i have
Item No Loc Type Quantity
231 A 1 34
and in second table
Item No Loc Type Quantity
231 A 1 11
231 A 1 12
231 A 1 11
Quantity in first table is sum of quantity in second table group by
item No, Loc, Type.
How i can link quantity from first table when press 34 to open second table with data how i got this 34?
Any idea???
Use a Pivot Table with row field Layout and Print settings set to "Show item labels in tabular form".
This will give you a table like this:
When you double-click the "34" a new sheet will be added showing the source data rows used to calculate the total quantity:
Use =sumifs() function.
see image for more details

Get average of cells conditionally in Excel 2010

I have a table in Excel with 2 columns. Column A (Owner) has a list of names. Column B (Duration) has a list of numbers. I need to get the average of numbers for each of the owner. So for James it would be (4 + 5 + 18) / 3. I know how to get the average in Excel but I don't know how to conditional say:
Use the value in Column B if value in A = "James"
A B
---------------
Owner Duration
James 4
Dan 67
Ger 3
James 5
Ger 75
James 18
The AVERAGEIF function will allow you to do this.
=AVERAGEIF(A2:A7,"James",B2:B7)
The first argument is the range which will be subject to the criteria
The second argument is the criteria.
The third argument is the range (corresponding to the first range) with values to be averaged.
There is also a SUMIF, COUNTIF, and others.
You will need to do this in a pivot table.
Select all your data.
Go to Insert >> pivot table >> click ok
Select both columns (COLA, COLB) from the list of fields
available on the right.
By default COLB will go under VALUES.
Click on the arrow that says Sum of COLB >> click on value field
settings >> Select Average function instead of sum.
Check this link https://support.office.com/en-us/article/Create-or-delete-a-PivotTable-or-PivotChart-report-d09e4d07-8cd6-4b60-afad-8fb67418800f?CorrelationId=78b545a8-649b-400a-9941-a23ef409c95b&ui=en-US&rs=en-US&ad=US#_Toc263767342 for more info on pivot tables

select the row with number most close to certain value

I have a set of data with 3 column (example shown in the figure). The second column (height) is starting from 1 and increased to ~80 and then starting from 1 again. I need to select the row with the second column most close to 50. As shown in the figure below, I will need to select 3 rows. Can any one suggest how to find out those rows in excel?
Many thanks!
=match(50, B1:B80, 1)
will find the element that has the largest value less than or equal to 50 in that range (choose your ranges accordingly). I believe B1:B80 must be in ascending order.

Resources