TOP N in a query

CKEEV

New Member
Joined
Aug 3, 2011
Messages
2
Hello,

Can someone please help me with a formula to show the Top 5 customers in given query broken out by Product Family? For Example: I want to see the top 5 customer sales for X product, the top 5 customers for Z product and so forth. I think I am having trouble grouping because it returns the top 5 customers overall, but not broken out by product family. Thanks for your help in advance. See the formula I am currently using below.

In (Select Top 5 [Pricing Quantity] From [Sales by Buying Group] Where [Product Family]=[Sales by Buying Group].[Product Family] Order By [Pricing Quantity] Desc)
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
This worked for me where tblSales had 3 fields Product, ProductGroup and SalesValue.

SELECT tblSales.Product, tblSales.ProductGroup, tblSales.SalesValue

FROM tblSales

WHERE tblSales.SalesValue In
(

SELECT TOP 5 SalesValue
FROM tblSales AS A
WHERE A.ProductGroup = tblSales.[ProductGroup]
ORDER BY SalesValue DESC
)

ORDER BY tblSales.ProductGroup, tblSales.SalesValue DESC;
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,896
Members
452,948
Latest member
Dupuhini

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