Fix Customer and Date Criteria in a Microsoft Access Union Query
Question details
Correct customer-name and date criteria in an Access union query that returns unexpected profitability percentages.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- The user wants to filter a union query for two customer names and specified report dates, and may also need a separate query for other customers.
- Observed behavior
- Profitability percentages are incorrect after customer-name and date filters are added.
Open the query in Access and identify each SELECT statement that needs the customer and date filters. Confirm whether RptDateStart and RptDateEnd should match the entered dates exactly or whether you need a date range instead.
Use IN to apply customer and date criteria together
Use IN to match either customer name while applying both date conditions to every matching row.
In Access SQL, AND is evaluated before OR. Without parentheses, date conditions may apply to only one of the customer-name alternatives.
In the Access Navigation Pane, right-click the union query and select SQL View.
In each applicable SELECT statement, use: WHERE CustomerName IN ('MERCURY PLASTICS OF', 'MERCURY PLASTICS, IN') AND RptDateStart = [Enter Start Date] AND RptDateEnd = [Enter End Date]. Keep the UNION structure and any other needed criteria intact.
Select Run, enter the requested dates, and check the returned customer rows and profitability percentages against the source data.

Exclude the two customers with NOT IN
Use a separate query to return customers other than the two named values.
Review Access Query Results in WPS Spreadsheets
WPS Office is a free, lightweight Office alternative with a familiar interface and Microsoft Office format compatibility. Export Access query results to a spreadsheet to review them in WPS; WPS does not fix or run the Access union query itself.

Frequently Asked Questions
Why did adding OR change the query results?
Access evaluates AND before OR, so an ungrouped OR can let one customer condition bypass the date criteria. Use CustomerName IN (...) or enclose the customer conditions in parentheses before adding AND date conditions.
Can I use OR instead of IN for the two customers?
Yes. In each applicable WHERE clause, use (CustomerName = 'MERCURY PLASTICS OF' OR CustomerName = 'MERCURY PLASTICS, IN') AND RptDateStart = [Enter Start Date] AND RptDateEnd = [Enter End Date].
Does NOT IN include records with a blank customer name?
It does not include Null customer names. To include them, group the condition as (CustomerName NOT IN (...) OR CustomerName IS NULL) and then add the date criteria with AND.
What if the profitability percentages are still wrong?
In SQL View, check the filters in every applicable SELECT and compare the returned rows with the source data. Also review whether UNION removes duplicate rows and whether the profitability calculation uses the intended totals.
Can WPS Office run the Access union query?
No. Edit and run the union query in Microsoft Access. To review the results in WPS Spreadsheets, export them from Access to an Excel file and open that file in WPS.




