问题
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.
回答1:
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)
回答2:
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
, SelectValue Filter
, SelectTop 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
来源:https://stackoverflow.com/questions/60938311/how-to-print-top-3-employees-in-a-region-in-excel