I'm working on a database that stores sales information. I have a query on said table that does a lot of calculations based on region. All of my salespeople have an id, a region they are in, sales numbers, success ratios, etc. The query I have designed is more concerned with the regions than the individual salespeople. So, when it runs it totals up all the total sales per region, the average success ratio in each region, weighted commission rates, and average sales size. It works well, but now I'm trying to sort it an I run into problems. Here's a segment of the query:
SELECT [Dealer Name], (SUM([Sales]*.[Commission])/Sum([Sales])) AS WeightedAverage, Sum([Sales])/Sum(IIf([Sales]>0,1,0)) AS AvgContract, Sum(IIf([Sales]>0,1,0))/Sum(IIf([status]='Sold',1,0)) AS SuccessRation FROM qryDealer
GROUP BY [Dealer Name]
ORDER BY WeightedAverage DESC;
Which doesn't work. I've tried replacing 'WeightedAverage' with '(SUM([Sales]*.[Commission])/Sum([Sales]))' and I get overflow erros. It does the weighted average calculation correctly, I just can't seem to get it to sort by that calculation.
What simple thought did I miss? It's always something simple it seems. LOL
SELECT [Dealer Name], (SUM([Sales]*.[Commission])/Sum([Sales])) AS WeightedAverage, Sum([Sales])/Sum(IIf([Sales]>0,1,0)) AS AvgContract, Sum(IIf([Sales]>0,1,0))/Sum(IIf([status]='Sold',1,0)) AS SuccessRation FROM qryDealer
GROUP BY [Dealer Name]
ORDER BY WeightedAverage DESC;
Which doesn't work. I've tried replacing 'WeightedAverage' with '(SUM([Sales]*.[Commission])/Sum([Sales]))' and I get overflow erros. It does the weighted average calculation correctly, I just can't seem to get it to sort by that calculation.
What simple thought did I miss? It's always something simple it seems. LOL