I currently have a union query that combines my data by year and Region:
SELECT
[Year], "UK" as Region, UK as Data from [4 Premium Analysis]
UNION SELECT [Year], "US", US from [4 Premium Analysis]
UNION SELECT [Year], "Other North America", Other_north_america from [4 Premium Analysis]
UNION SELECT [Year], "Western Europe", Western_europe from [4 Premium Analysis]
UNION SELECT [Year], "Eastern Europe", Eastern_europe from [4 Premium Analysis]
UNION SELECT [Year], "Asia", Asia from [4 Premium Analysis]
UNION SELECT [Year], "Australia & New Zealand", Australia_new_zealand from [4 Premium Analysis]
UNION SELECT [Year], "Bermuda", Bermuda from [4 Premium Analysis]
UNION SELECT [Year], "Rest of World", Rest_world from [4 Premium Analysis];
I then call this Union query in a crosstab query to get a summary of premiums by year and region for the past 5 years:
TRANSFORM Sum([Union Query - Five Year Geographic Region].Data) AS SumOfData
SELECT [Union Query - Five Year Geographic Region].Region AS Region
FROM [Union Query - Five Year Geographic Region]
WHERE ((([Union Query - Five Year Geographic Region].Year)>=(SELECT max([Year]) - 4 from [Union Query - Five Year Geographic Region]) And ([Union Query - Five Year Geographic Region].Year)<=(SELECT max([Year]) from [Union Query - Five Year Geographic Region])))
GROUP BY [Union Query - Five Year Geographic Region].Region
ORDER BY [Union Query - Five Year Geographic Region].Year
PIVOT [Union Query - Five Year Geographic Region].Year;
My problem is that there are some companies which do not have current data and I wish to exclude them from the summary result of the crosstab query. e.g. Companys A,B and C all submitted data for the current year 2005. Company D did not submit data for 2005 but its data from 2004, 2003, 2002 and 2001 are included in those year's totals in the crosstab query. How can I get the query (either the union or crosstab) to only pull data from companies who have current year data in the database.
SELECT
[Year], "UK" as Region, UK as Data from [4 Premium Analysis]
UNION SELECT [Year], "US", US from [4 Premium Analysis]
UNION SELECT [Year], "Other North America", Other_north_america from [4 Premium Analysis]
UNION SELECT [Year], "Western Europe", Western_europe from [4 Premium Analysis]
UNION SELECT [Year], "Eastern Europe", Eastern_europe from [4 Premium Analysis]
UNION SELECT [Year], "Asia", Asia from [4 Premium Analysis]
UNION SELECT [Year], "Australia & New Zealand", Australia_new_zealand from [4 Premium Analysis]
UNION SELECT [Year], "Bermuda", Bermuda from [4 Premium Analysis]
UNION SELECT [Year], "Rest of World", Rest_world from [4 Premium Analysis];
I then call this Union query in a crosstab query to get a summary of premiums by year and region for the past 5 years:
TRANSFORM Sum([Union Query - Five Year Geographic Region].Data) AS SumOfData
SELECT [Union Query - Five Year Geographic Region].Region AS Region
FROM [Union Query - Five Year Geographic Region]
WHERE ((([Union Query - Five Year Geographic Region].Year)>=(SELECT max([Year]) - 4 from [Union Query - Five Year Geographic Region]) And ([Union Query - Five Year Geographic Region].Year)<=(SELECT max([Year]) from [Union Query - Five Year Geographic Region])))
GROUP BY [Union Query - Five Year Geographic Region].Region
ORDER BY [Union Query - Five Year Geographic Region].Year
PIVOT [Union Query - Five Year Geographic Region].Year;
My problem is that there are some companies which do not have current data and I wish to exclude them from the summary result of the crosstab query. e.g. Companys A,B and C all submitted data for the current year 2005. Company D did not submit data for 2005 but its data from 2004, 2003, 2002 and 2001 are included in those year's totals in the crosstab query. How can I get the query (either the union or crosstab) to only pull data from companies who have current year data in the database.