Top 3 items based on criteria

Rolly_Sefu

Board Regular
Joined
Oct 25, 2013
Messages
149
Hello

I want to know how can I get a TOP 3 for column FRUIT for the month JAN based on the criteria 2.

Top 1 : Apple : 5
Top 2 : Orange : 2
Top 3 : Banana : 1

I have the following table:

ABCDEFGHI
1JanJanJanJanFebFebFeb
2RegionFruitWK1WK2WK3WK4WK5WK6WK7
3Region1apple222
4Region1banana1
5region1orange2
6region2apple2
7region3apple2
8region3banana2
9region3orange12

<tbody>
</tbody>
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
1. "based on the criteria 2."

What does criteria 2 mean ?

2. How do you get 5 apples ?

Or 2 oranges for that matter ?
 
Last edited:
Upvote 0
Hy, sorry, Criteria: "2" , the 2 is a value in the cell

Apple is TOP 1 for Jan => sum all 2's in WK1 to WK4 and you get 5.
 
Upvote 0
For apples: If you sum all 2s in WK1 to WK5 you get 10 2+2+2+2+2

If however you COUNT the number of 2s for apples you get 5.
 
Last edited:
Upvote 0
Here's a start

in J3
=SUMPRODUCT((B$3:B$9=J3)*(C$3:I$9=2))
Array formula, use Ctrl-Shift-Enter
copy down for as many rows as you have in column B

in K3
=SUMPRODUCT((B$3:B$9=J3)*(C$3:I$9=2))
copy down for as many rows as you have in column B
 
Upvote 0
#4 : Yes, sorry I was thinking about count.

#5 : the problem is that I need to TOP 3, but I only have the data. I have to find out the top 3 value and the names for the values.

The example I posted is short but my list is much larger.
 
Upvote 0
If I do this: "in J3 =SUMPRODUCT((B$3:B$9=J3)*(C$3:I$9=2)) " I get a circular formula error, since I put in in J3

From #1 the top 3 is the desired result.

"
Top 1 : Apple : 5
Top 2 : Orange : 2
Top 3 : Banana : 1
"
 
Last edited:
Upvote 0
Oops!

in J3
=IFERROR(INDEX($B$3:$B$9,SMALL(IF((COUNTIF(B$3:B3,B3)=1),ROW($A$3:$A$9)),ROW(A1))-(ROW(A$3)-1),1),"")
Array formula, use Ctrl-Shift-Enter

Not sure how to develop this further.

What happens if you get a tie ? What result would you expect then if apples and oranges were the same total ?
 
Upvote 0
I managed to create a formula but not working as I would like it to:

Code:
=INDEX($B$3:$B$9;SMALL(IF(N(IF(1;IFERROR(MATCH(IF($C$3:$F$9=2;$B$3:$B$9;0);$B$3:$B$9;0);FALSE);0))=0;"";N(IF(1;IFERROR(MATCH(IF($C$3:$F$9=2;$B$3:$B$9;0);$B$3:$B$9;0);FALSE);0)));ROW(A1)))
'I get all the result but not in top order and they are multiplied, as you copy down

Code:
=INDEX($B$3:$B$9;MATCH(1;INDEX(($D$3:$D$9=LARGE(IF($D$3:$D$9=2;$D$3:$D$9;0);ROWS($H$12:H12)))*(COUNTIF($H$12:H12;$B$3:$B$9)=0););0))
'these are not in order, and I still need the number, and is gives an error when I try to add column ( since jan has more columns)

#8 : if I get a tie
Top 1 apples: 2
Top 2 oranges: 2
is OK
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top