Solved

Getting a Totals Query to show 0 values

Posted on 2006-11-03
1
272 Views
Last Modified: 2012-06-27
I have a report that has a graph.  The data source for the graph is a query.  I want to have the graph legend show all of the catagories, even if the count is zero.  What is the best way to do this?  The method I've tried, and it does not work, is to create two queries (Named Query2 and AllZeros) that feed a 3rd query (Query3), and then use the 3rd query as the datasource for the graph.

Here is the code for each query:

***All Zeros (The job of this query is to set a zero value for each catagory.  It successfully reports 0 for all catagories):
SELECT Format([Date],"ww/yyyy") AS Week, [List: Factories].Supplier, [List: Errors].[Error Catagory], 0 AS [Error Count]
FROM [List: Errors], [List: Factories], [Rework Errors]
GROUP BY Format([Date],"ww/yyyy"), [List: Factories].Supplier, [List: Errors].[Error Catagory], 0;

***Query2 (The job of this query is to report the actual count of rework errors, which it does correctly):
PARAMETERS [Forms]![Menu]![StartDate] DateTime, [Forms]![Menu]![EndDate] DateTime;
SELECT [Rework Errors].Factory, Format([Date],"ww/yyyy") AS [Week/Year], [Rework Errors].[Error Catagory], Count([Rework Errors].[Error Catagory]) AS [CountOfError Catagory]
FROM [Rework Errors]
WHERE ((([Rework Errors].Date) Between [Forms]![Menu]![StartDate] And [Forms]![Menu]![EndDate]))
GROUP BY [Rework Errors].Factory, Format([Date],"ww/yyyy"), [Rework Errors].[Error Catagory]
ORDER BY Format([Date],"ww/yyyy"), Count([Rework Errors].[Error Catagory]) DESC;

***Query3 (now, for some reason i thought if you added together the 0 value from the "allzeros" query and the error count from "query2", you would get a display of all catagories, even if they are zero value, however this is not the case):
SELECT Query2.Factory, Query2.[Week/Year], Query2.[Error Catagory], IIf(([All Zeros]![Error Count]+Query2![CountOfError Catagory])=0,0,([All Zeros]![Error Count]+Query2![CountOfError Catagory])) AS Expr1
FROM [All Zeros] INNER JOIN Query2 ON ([All Zeros].Week = Query2.[Week/Year]) AND ([All Zeros].[Error Catagory] = Query2.[Error Catagory]) AND ([All Zeros].Supplier = Query2.Factory)
GROUP BY Query2.Factory, Query2.[Week/Year], Query2.[Error Catagory], IIf(([All Zeros]![Error Count]+Query2![CountOfError Catagory])=0,0,([All Zeros]![Error Count]+Query2![CountOfError Catagory]));


What is the best way to accomplish this?  I want all catagories to be displayed in teh query, even if they are 0 value.
0
Comment
Question by:loscomp
1 Comment
 
LVL 54

Accepted Solution

by:
nico5038 earned 250 total points
ID: 17866531
The basic approach will be to have a mandatory list of categories and JOIN this list/table with the data using an OUTER JOIN being a "LEFT" or "RIGHT" join in Access.
Just use the graphical query editor and doubleclick the JOIN line to select option 2 or 3 to make the categories "leading"

Getting the idea ?

Nic;o)
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now