I have a union query to, both tables have a date formatted as "yyyy mm" to group records by month, I need to combine the PaidTime from tblDuties and PaidTimeAnnualLeave from tblAnnualLeave as AveragePaidTime
However I get two different entries when rinning the query, the below example should combine 2024 12 and 2025 01.
What would be the correct code?
Code:
SELECT Format([DutyDate],"yyyy mm") AS YearMonth,
Avg(tblDuties.PaidTime) AS AveragePaidTime,
Avg(tblDuties.SpreadTime) AS AverageSpreadTime,
Avg(tblDuties.BreakTime) AS AverageBreakTime,
Avg(tblDuties.Overtime) AS AverageOvertime
FROM tblDuties
GROUP BY Format([DutyDate],"yyyy mm")
UNION SELECT Format([AnnualLeaveDate],"yyyy mm") AS YearMonth,
Avg(tblAnnualLeave.PaidTimeAnnualLeave) AS AveragePaidTime,
Null AS AverageSpreadTime,
Null AS AverageBreakTime,
Null AS AverageOvertime
FROM tblAnnualLeave
GROUP BY Format([AnnualLeaveDate],"yyyy mm")
ORDER BY YearMonth;
However I get two different entries when rinning the query, the below example should combine 2024 12 and 2025 01.
What would be the correct code?