I got some help last week with a crosstab query and thanks to that I have now been able to create the query that I need.
I am now creating a report based on the query and have encountered a problem. I am posting here in the query forum as I think it is the query that needs fixing and not a report issue.
First of all here is the query
CODE
TRANSFORM Sum(CCur([intFV])) AS Expr1
SELECT Year([CallDate]) AS [Year], Format([CallDate],"ww") AS Week, Calls.CallDate, Sum(CCur([intFV])) AS Vouchers, Sum(Calls.intTV) AS Telstra, Count(Contacts.ContactID) AS [# of Clients], Count(Calls.CallID) AS [# of Interviews], Sum(IIf([MinOfCallDate]=[CallDate],1,0)) AS [New Contacts]
FROM tblPayments INNER JOIN ((Contacts INNER JOIN Qfirst_contact ON Contacts.ContactID = Qfirst_contact.ContactID) INNER JOIN Calls ON Contacts.ContactID = Calls.ContactID) ON tblPayments.ID = Contacts.PaymentType
WHERE (((Year([CallDate]))=2012))
GROUP BY Year([CallDate]), Format([CallDate],"ww"), Calls.CallDate
ORDER BY Calls.CallDate
PIVOT tblPayments.Payment;
SELECT Year([CallDate]) AS [Year], Format([CallDate],"ww") AS Week, Calls.CallDate, Sum(CCur([intFV])) AS Vouchers, Sum(Calls.intTV) AS Telstra, Count(Contacts.ContactID) AS [# of Clients], Count(Calls.CallID) AS [# of Interviews], Sum(IIf([MinOfCallDate]=[CallDate],1,0)) AS [New Contacts]
FROM tblPayments INNER JOIN ((Contacts INNER JOIN Qfirst_contact ON Contacts.ContactID = Qfirst_contact.ContactID) INNER JOIN Calls ON Contacts.ContactID = Calls.ContactID) ON tblPayments.ID = Contacts.PaymentType
WHERE (((Year([CallDate]))=2012))
GROUP BY Year([CallDate]), Format([CallDate],"ww"), Calls.CallDate
ORDER BY Calls.CallDate
PIVOT tblPayments.Payment;
The problem I am having is that it only lists headings from the tblPayments table where it is not null.
To better explain (hopefully)
The report works fine when I run it on the entire data set, as there is atleast 1 entry for each of the headers coming from the tblPayments table.
When I alter the query to include only a small date range, then I have a problem.
For example, one of the headers coming from the tblePayments table is "Breached", but if there are no entries for Breached in the date range I select then the heading for Breached is not included in the query results.
This causes a problem as the report has a field for Breached and complains that it isn't there.
I assume I need to alter the query to list all entries from tblPayments and not just those that are used.
As I've written this I've also wondered if it is a report thing and I need to set the report fields to be ignored somehow if the data field doesn't exist.
Thanks in advance
Brendan