How do I aggregate by customers with sales greater than or equal to x dollars - MS Access 2010 with SQL statment

anich22

New Member
Joined
Jun 3, 2013
Messages
5
Currently I have a query that captures all sales for specific manufacturing codes within a date range.

I would like to capture only those customers that have sales greater than x dollars, for the same mfg codes and date range. Would I have to create a maketable of the first data, aggregate by customer to obtain my solution or is there a one step method in the same query. MS Access SQL statment is below.

SELECT dbo_vw_Dimension_CalendarDate.MonthsAgo, dbo_vw_Dimension_CalendarDate.YearSeq AS [Year], Left([CalendarMonth],(InStr([calendarmonth]," ")-1)) AS [Month], Left([Calendarquarter],(InStr([calendarquarter]," ")-1)) AS Quarter, dbo_vw_Dimension_CalendarDate.CalendarDate AS InvoiceDate, dbo_vw_Dimension_Customer.CustomerCodeINT, dbo_vw_Dimension_Customer.CustomerShortDescription, dbo_vw_Fact_Invoice_Detail.InvoiceCode, dbo_vw_Fact_Invoice_Detail.InvoiceLineSeq, dbo_vw_Dimension_Order.OrderCode, dbo_vw_Fact_Invoice_Detail.ReferenceCode, dbo_vw_Fact_Invoice_Detail.SalesQuantity, dbo_vw_Fact_Invoice_Detail.SalesDollarAmount, dbo_vw_Dimension_Product.ItemCode, dbo_vw_Dimension_Product.ItemDescription, dbo_vw_Dimension_Product.ItemTypeCode, dbo_vw_Dimension_Product.ItemTypeDescription, dbo_vw_Dimension_Product.ItemClassCode, dbo_vw_Dimension_Product.ItemClassDescription, dbo_vw_Dimension_Product.BrandDescription, dbo_vw_Dimension_Product.ManufacturerCode, dbo_vw_Dimension_Product.ManufacturerDescription, dbo_vw_Dimension_Product.ItemManufacturerPartNumber, dbo_vw_Dimension_Coworker_AccountManager.AccountManagerCode, dbo_vw_Dimension_Coworker_AccountManager.CoworkerCode, dbo_vw_Dimension_Coworker_AccountManager.CoworkerName, dbo_vw_Dimension_Coworker_AccountManager.ManagerCoworkerCode, dbo_vw_Dimension_Coworker_AccountManager.ManagerCoworkerName, dbo_vw_Dimension_Coworker_Manager.EMailAddress AS MgrEmail, dbo_vw_Dimension_Coworker_AccountManager.TerminationFlag, dbo_vw_Dimension_Coworker_AccountManager.TerminationDescription, dbo_vw_Dimension_Coworker_AccountManager.CoworkerGLLevel4Alias, dbo_vw_Dimension_Coworker_AccountManager.CoworkerGLLevel5Alias, dbo_vw_Dimension_Coworker_AccountManager.CoworkerGLLevel6Alias, dbo_vw_Dimension_Coworker_AccountManager.CoworkerGLLevel7Alias, dbo_vw_Dimension_Coworker_AccountManager.CoworkerGLLevel8Alias, dbo_vw_Dimension_Coworker_AccountManager.CoworkerGLLevel9Alias, dbo_vw_Dimension_Coworker_AccountManager.CoworkerGLLevel10Alias, dbo_vw_Dimension_Coworker_AccountManager.CoworkerGLLevel11Alias, dbo_vw_Dimension_Coworker_AccountManager.CoworkerGLLevel12Alias INTO Aletha75Kinvoice
FROM dbo_vw_Dimension_Order INNER JOIN (dbo_vw_Dimension_Coworker AS dbo_vw_Dimension_Coworker_Manager INNER JOIN (dbo_vw_Dimension_Commissionable INNER JOIN (dbo_vw_Dimension_Coworker_AccountManager INNER JOIN (dbo_vw_Dimension_Company INNER JOIN (dbo_vw_Dimension_Customer INNER JOIN (dbo_vw_Dimension_CalendarDate INNER JOIN (dbo_vw_Dimension_Product INNER JOIN dbo_vw_Fact_Invoice_Detail ON dbo_vw_Dimension_Product.ItemSeq = dbo_vw_Fact_Invoice_Detail.ItemSeq) ON dbo_vw_Dimension_CalendarDate.DateSeq = dbo_vw_Fact_Invoice_Detail.InvoiceDateSeq) ON dbo_vw_Dimension_Customer.CustomerSeq = dbo_vw_Fact_Invoice_Detail.OriginalCustomerSeq) ON dbo_vw_Dimension_Company.CompanySeq = dbo_vw_Fact_Invoice_Detail.CompanySeq) ON dbo_vw_Dimension_Coworker_AccountManager.AccountManagerSeq = dbo_vw_Dimension_Customer.PrimaryAccountManagerSeq) ON dbo_vw_Dimension_Commissionable.CommissionableSeq = dbo_vw_Fact_Invoice_Detail.CommissionableSeq) ON dbo_vw_Dimension_Coworker_Manager.CoworkerSeq = dbo_vw_Dimension_Coworker_AccountManager.ManagerCoworkerSeq) ON dbo_vw_Dimension_Order.OrderSeq = dbo_vw_Fact_Invoice_Detail.OrderSeq
WHERE (((dbo_vw_Dimension_CalendarDate.MonthsAgo)=0 Or (dbo_vw_Dimension_CalendarDate.MonthsAgo)=1 Or (dbo_vw_Dimension_CalendarDate.MonthsAgo)=2) AND ((dbo_vw_Dimension_Product.BrandDescription)="microsoft") AND ((dbo_vw_Dimension_Product.ManufacturerCode) In ("MSA ","MA6 ","MB6 ","MC6 ","MD6 ","MLG ","MG6 ","MLE ","MLA ","MLB ","MLC ","MLD ","S+D ","M+M ","M+G ","M+A ","M+B ","M+C ","M+D ","M+S ","MSU")) AND ((dbo_vw_Fact_Invoice_Detail.CommissionableSeq)=1) AND ((dbo_vw_Dimension_Company.CompanyTypeDescription)="sales") AND ((dbo_vw_Dimension_Company.CountryCode)="us"));
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Is this pulling data from SQL Server?
If so, you could either design a view in SQL Server to do the aggregation, or turn this into a make-table and analyse the result.

Denis
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,294
Members
449,077
Latest member
Rkmenon

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