Ranking Sales and pulling only top 100

nah225

New Member
Joined
Jul 13, 2004
Messages
17
Is there a way to pull only the top 100 (or whatever #) items by sales $ within my query? I have the sales $ listed in descending order, but there are over 10000 items and rather than manually pull out the top 100, I'd like to have it automatically.

I don't want it to necessarily rank them to where I get 1,2,2,4, but rather 1,2,3,4....100.

TI hope this is clear -thanks!
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
In your query where the sales are ranked, make sure they are sorted Descending -- this gives biggest values first.
Now, still in Design view, there is a Top Values box just under the toolbars. Enter 100 in the box, press Enter, adn you're done.

Denis
 
Upvote 0
What if you wanted to take the query a step further and report the top 100 within each and every state????
 
Upvote 0
Good question! :biggrin:

I don't think it's possible in a query but it can be achieved in a report. You'll need to set the report to group by State and sort descending by Value. This code comes from the Microsoft Knowledge Base --

Code:
Option Compare Database 'Use database order for string comparisons.
Option Explicit
Global TotCount As Integer

' Call the SetCount() function from the group header section's
' OnPrint property using the syntax: =SetCount(Report)

Function SetCount (R As Report)
   TotCount = 0
   R![ProductName].Visible = True
End Function

' Call the PrintLines() function from the detail section's OnPrint
' property using the syntax: =PrintLines(Report,[TotGrp]).

Function PrintLines (R As Report, TotGrp)
   TotCount = TotCount + 1
   If TotCount = TotGrp Then
        R.NextRecord = False
   ElseIf TotCount > TotGrp And TotCount < 15 Then
        R.NextRecord = False
        R![ProductName].Visible = False
   End If
End Function
You'll notice this row:ElseIf TotCount > TotGrp And TotCount < 15 Then which limits the # of rows pre group to 15. Try changing the number. Here's the link to the full article: http://support.microsoft.com/default.aspx?scid=kb;en-us;210350

Denis
 
Upvote 0

Forum statistics

Threads
1,221,814
Messages
6,162,135
Members
451,743
Latest member
matt3388

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