Hi
I was hoping for a bit of help. I have a table of profits made by product. Each product is in a section. I have a query to sum up profit made by section (excluding some sections by using HAVING). I then calculate at the section level the percent profit and want to order the results by biggest profit first. My query so far is:
Code:
SELECT TONYProductProfitabilityTable.[Product Section Name], First(TONYProductProfitabilityTable.[Product Price Type]) AS [FirstOfProduct Price Type], Sum(TONYProductProfitabilityTable.CostofStockLeft) AS SumOfCostofStockLeft, Sum(TONYProductProfitabilityTable.CostValueofUnitsSold) AS SumOfCostValueofUnitsSold, Sum(TONYProductProfitabilityTable.CurrentProductProfit) AS SumOfCurrentProductProfit, IIf(SumOfCostValueofUnitsSold>0,Round((SumOfCurrentProductProfit/SumOfCostValueofUnitsSold)*100,2),0) AS PrecentProfitonSoldUnits, IIf(SumOfCostofStockLeft>0 And SumOfCostValueofUnitsSold>0,Round(SumOfCostofStockLeft/(SumOfCostValueofUnitsSold+SumOfCostofStockLeft)*100,2), IIf(SumOfCostofStockLeft=0 And SumOfCostValueofUnitsSold>0,0,100)) AS PercentStockLeft
FROM TONYProductProfitabilityTable
GROUP BY TONYProductProfitabilityTable.[Product Section Name]
HAVING (((First(TONYProductProfitabilityTable.ProductReportingType))<>'Gift Voucher' And (First(TONYProductProfitabilityTable.ProductReportingType))<>'Fabric Basics' );
I need to sort the results by biggest profit (IIf(SumOfCostValueofUnitsSold>0,Round((SumOfCurre ntProductProfit/SumOfCostValueofUnitsSold)*100,2),0) AS PrecentProfitonSoldUnits) but cant find a away to express it to make sql understand.
Any ideas of how to do this?
Many thanks
Tony