Re: Cross Tab Query and Totals
Hi,
What I did first was to create a cross tab query as below,
TRANSFORM Sum(Tbl_Expenditure.Amount) AS SumOfAmount
SELECT Tbl_Main.Date
FROM Tbl_Main INNER JOIN Tbl_Expenditure ON Tbl_Main.MainID = Tbl_Expenditure.MainID
GROUP BY Tbl_Main.MainID, Tbl_Main.Date
ORDER BY Tbl_Main.Date
PIVOT Tbl_Expenditure.Description;
Then I created the below query,
SELECT Tbl_Main.MainID, Tbl_Main.ChequeNumber, Qry_ExpenditureCrossTab.Date, Qry_ExpenditureCrossTab.[Friday Night Comp], Qry_ExpenditureCrossTab.Miscellaneous, Qry_ExpenditureCrossTab.Suppers, Qry_ExpenditureCrossTab.Functions, Qry_ExpenditureCrossTab.Drinks, Qry_ExpenditureCrossTab.Prizes, Qry_ExpenditureCrossTab.Trophies, Qry_ExpenditureCrossTab.[Inter Club Fees], [Friday Night Comp ]+[Miscellaneous]+[Suppers]+[Functions]+[Drinks]+[Prizes]+[Trophies]+[Inter Club Fees] AS Total
FROM Tbl_Main INNER JOIN Qry_ExpenditureCrossTab ON Tbl_Main.Date = Qry_ExpenditureCrossTab.Date;
The above query works if there are values in each of the fields if there are null values it will not add up the total.
I know I will need to make the values default to 0 but I am not sure how to do this.
I have read some of the other threads on this subject but I have found it difficult to apply to my situation.
Thank you to anybody who can help me with this.
Hi,
What I did first was to create a cross tab query as below,
TRANSFORM Sum(Tbl_Expenditure.Amount) AS SumOfAmount
SELECT Tbl_Main.Date
FROM Tbl_Main INNER JOIN Tbl_Expenditure ON Tbl_Main.MainID = Tbl_Expenditure.MainID
GROUP BY Tbl_Main.MainID, Tbl_Main.Date
ORDER BY Tbl_Main.Date
PIVOT Tbl_Expenditure.Description;
Then I created the below query,
SELECT Tbl_Main.MainID, Tbl_Main.ChequeNumber, Qry_ExpenditureCrossTab.Date, Qry_ExpenditureCrossTab.[Friday Night Comp], Qry_ExpenditureCrossTab.Miscellaneous, Qry_ExpenditureCrossTab.Suppers, Qry_ExpenditureCrossTab.Functions, Qry_ExpenditureCrossTab.Drinks, Qry_ExpenditureCrossTab.Prizes, Qry_ExpenditureCrossTab.Trophies, Qry_ExpenditureCrossTab.[Inter Club Fees], [Friday Night Comp ]+[Miscellaneous]+[Suppers]+[Functions]+[Drinks]+[Prizes]+[Trophies]+[Inter Club Fees] AS Total
FROM Tbl_Main INNER JOIN Qry_ExpenditureCrossTab ON Tbl_Main.Date = Qry_ExpenditureCrossTab.Date;
The above query works if there are values in each of the fields if there are null values it will not add up the total.
I know I will need to make the values default to 0 but I am not sure how to do this.
I have read some of the other threads on this subject but I have found it difficult to apply to my situation.
Thank you to anybody who can help me with this.