Hi,
I have an Access union query that is supposed to select all results in the table that meet two criteria (falling between a particular date range and having a certain value in the CustomerName field) and calculate what percentage of it is profitable or not
(so, a value more or less than zero in my Profitability$ field). The first part of the union query calculates what percentage isn't profitable, the second part of the union query calculates what percentage is, and I use these two values to make a pie chart.
Currently my SQL looks like this:
PARAMETERS [Enter Start Date (mm/dd/yyyy):] DateTime, [Enter End date (mm/dd/yyyy):] DateTime;
SELECT COUNT(CustomerName)/
(SELECT COUNT(CustomerName)
FROM Untitled
WHERE CustomerName = 'MERCURY PLASTICS OF' OR 'MERCURY PLASTICS, IN'
AND RptDateStart = [Enter Start Date (mm/dd/yyyy):]
AND RptDateEnd = [Enter End date (mm/dd/yyyy):])*100 AS Percentage
FROM Untitled
WHERE CustomerName = 'MERCURY PLASTICS OF' OR 'MERCURY PLASTICS, IN'
AND [Profitability$]< 0
AND RptDateStart = [Enter Start Date (mm/dd/yyyy):]
AND RptDateEnd = [Enter End date (mm/dd/yyyy):]
UNION SELECT COUNT(CustomerName)/
(SELECT COUNT(CustomerName)
FROM Untitled
WHERE CustomerName = 'MERCURY PLASTICS OF' OR 'MERCURY PLASTICS, IN'
AND RptDateStart = [Enter Start Date (mm/dd/yyyy):]
AND RptDateEnd = [Enter End date (mm/dd/yyyy):])*100 AS Percentage
FROM Untitled
WHERE CustomerName = 'MERCURY PLASTICS OF' OR 'MERCURY PLASTICS, IN'
AND [Profitability$]>=0
AND RptDateStart = [Enter Start Date (mm/dd/yyyy):]
AND RptDateEnd = [Enter End date (mm/dd/yyyy):];
It's working -- that is to say it's calculating -- but it's coming up with incorrect numbers. Previously, before the CustomerName category was relevant and only the date range mattered, I was using this:
PARAMETERS [Enter Start Date (mm/dd/yyyy):] DateTime, [Enter End date (mm/dd/yyyy):] DateTime;
SELECT COUNT(*)/
(SELECT COUNT(*)
FROM Untitled
WHERE RptDateStart = [Enter Start Date (mm/dd/yyyy):]
AND RptDateEnd = [Enter End date (mm/dd/yyyy):])*100 AS Percentage
FROM Untitled
WHERE [Profitability$]< 0
AND RptDateStart = [Enter Start Date (mm/dd/yyyy):]
AND RptDateEnd = [Enter End date (mm/dd/yyyy):]
UNION SELECT COUNT(*)/
(SELECT COUNT(*)
FROM Untitled
WHERE RptDateStart = [Enter Start Date (mm/dd/yyyy):]
AND RptDateEnd = [Enter End date (mm/dd/yyyy):])*100 AS Percentage
FROM Untitled
WHERE [Profitability$]>=0
AND RptDateStart = [Enter Start Date (mm/dd/yyyy):]
AND RptDateEnd = [Enter End date (mm/dd/yyyy):];
Which worked perfectly. Does anyone have some advice to offer?