Solved

Getting a Totals Query to show 0 values

Posted on 2006-11-03
1
271 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.

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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…

747 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

9 Experts available now in Live!

Get 1:1 Help Now