I Would Like my Count Field Query to Return Zeroes for Dates With No Data Instead of Simply Not Listing That Date
I seem to have a continuous problem with this. I have a table with ALL possible dates (They are actually all Week Ending Saturday Dates.)
I have another table with actual data and the Week Ending Saturday Date associated with that piece of data.
My query is a joining query that uses ALL of the possible dates. However it does not seem to be doing that. There are weeks missing. I have my SQL below
SELECT Count(NZ(B_ClosedByWeek_CARs_Tbl.CAR_Num_Full,0)) AS Closed, CAR_Possible_WEDATES_W_Leaps_tbl.PossibleWeekEndingDates AS Week INTO C3_ClosedbyWeek_KOJ_Time_Line_Count_tblFROM B_ClosedByWeek_CARs_Tbl RIGHT JOIN CAR_Possible_WEDATES_W_Leaps_tbl ON B_ClosedByWeek_CARs_Tbl.WEDate = CAR_Possible_WEDATES_W_Leaps_tbl.PossibleWeekEndingDatesWHERE (((B_ClosedByWeek_CARs_Tbl.Problem_Location)="KOJ Cherry St" Or (B_ClosedByWeek_CARs_Tbl.Problem_Location)="KOJ Panel Plant" Or (B_ClosedByWeek_CARs_Tbl.Problem_Location)="KOJ Wood Plant") AND ((B_ClosedByWeek_CARs_Tbl.WEDate)<Now() And (B_ClosedByWeek_CARs_Tbl.WEDate)>#5/31/2010#))GROUP BY CAR_Possible_WEDATES_W_Leaps_tbl.PossibleWeekEndingDatesORDER BY CAR_Possible_WEDATES_W_Leaps_tbl.PossibleWeekEndingDates;
It's taking me a bit to get my brain wrapped around your last comment, trying to visualize what you are describing. It's one of the more challenging questions I've seen posted here in a while :)
If I'm understanding correcly, the 'missing' records you want have nothing in the Plant field and nothing in the date field, beause there is no data from your main table corresponding to the right-joined data in your "all dates" table.
You might be able to resolve this by revising your plant criteria to allow NULL plants, or maybe a combination of Null Dates and Null plants
Like this:
WHERE ((B_ClosedByWeek_CARs_Tbl.Problem_Location="KOJ Cherry St" Or B_ClosedByWeek_CARs_Tbl.Problem_Location="KOJ Panel Plant" Or B_ClosedByWeek_CARs_Tbl.Problem_Location="KOJ Wood Plant" OR B_ClosedByWeek_CARs_Tbl.Problem_Location IS NULL) etc...
Or This:
WHERE ((B_ClosedByWeek_CARs_Tbl.Problem_Location="KOJ Cherry St" Or B_ClosedByWeek_CARs_Tbl.Problem_Location="KOJ Panel Plant" Or B_ClosedByWeek_CARs_Tbl.Problem_Location="KOJ Wood Plant" OR (B_ClosedByWeek_CARs_Tbl.Problem_Location IS NULL AND B_ClosedByWeek_CARs_Tbl.WEDate IS NULL)) etc...
Try changing your criteria to include NULL values for WEDate.
With your right join, these will be NULL for dates that are not present.
I think this will do it for your WHERE clause:
WHERE (((B_ClosedByWeek_CARs_Tbl.Problem_Location)="KOJ Cherry St" Or (B_ClosedByWeek_CARs_Tbl.Problem_Location)="KOJ Panel Plant" Or (B_ClosedByWeek_CARs_Tbl.Problem_Location)="KOJ Wood Plant") AND (((B_ClosedByWeek_CARs_Tbl.WEDate)<Now() And (B_ClosedByWeek_CARs_Tbl.WEDate)>#5/31/2010#) OR B_ClosedByWeek_CARs_Tbl.WEDate IS NULL))
No. That didn't workl. It's Still skipping some weeks. I thought a Join with a list of possible dates would return nulls for those weeks for which no data existed...not just skip them.
0
Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.
Take out the date criteria altogether (I realize this will not yield the correct results).
Do the missing weeks show up with the date criteria gone?
0
Rex85Author Commented:
Yes. You are correct. It is the WHERE clause. I'm not sure how, or if, I can get there from here. I may need to split the data table into a separate table for each location. As soon as I stipulate the location inclusion in the WHERE, it skips the blanks because they aren't associated with the blank dates....because they're blank. blank-dates-no-criteria.jpg
Instead of using the WEDate from the table that has missing weeks, use the PossiblWeekEndingDate from the table with all of the dates as your criteria. Like this:
((CAR_Possible_WEDATES_W_Leaps_tbl.PossibleWeekEndingDates)<Now() And (CAR_Possible_WEDATES_W_Leaps_tbl.PossibleWeekEndingDates)>#5/31/2010#))
SELECT Count(NZ(B_ClosedByWeek_CARs_Tbl.CAR_Num_Full,0)) AS Closed,
CAR_Possible_WEDATES_W_Leaps_tbl.PossibleWeekEndingDates AS Week
INTO C3_ClosedbyWeek_KOJ_Time_Line_Count_tbl
FROM CAR_Possible_WEDATES_W_Leaps_tbl
LEFT OUTER JOIN B_ClosedByWeek_CARs_Tbl ON B_ClosedByWeek_CARs_Tbl.WEDate = CAR_Possible_WEDATES_W_Leaps_tbl.PossibleWeekEndingDates
WHERE (B_ClosedByWeek_CARs_Tbl.Problem_Location="KOJ Cherry St"
Or B_ClosedByWeek_CARs_Tbl.Problem_Location="KOJ Panel Plant"
Or B_ClosedByWeek_CARs_Tbl.Problem_Location="KOJ Wood Plant")
AND B_ClosedByWeek_CARs_Tbl.WEDate BETWEEN #5/31/2010# AND Now()
GROUP BY CAR_Possible_WEDATES_W_Leaps_tbl.PossibleWeekEndingDates
ORDER BY CAR_Possible_WEDATES_W_Leaps_tbl.PossibleWeekEndingDates
0
Rex85Author Commented:
lludden:
Thank you, but that still skips the weeks that are nulls. (See Below)
I tried a double join, joining the data with both the possible dates and the possible locations, but Access couldn't handle it. It gave me the "ambiguous join" message that I needed to use a subquery. I have yet to successfully put one of those together. Skipped-Dates-2.jpg
Thank you. Yes. I did. It did not make a difference. When I removed the plant location, it showed the problem.
The data is in the form of Plant Date CAR_Number
When I join that data with the Possible Dates, but don't restrict the Plant, I get the nulls. That is what I want. However, since it only returns one null for a given possible date, and that is not associated with a plant location, by restricting location in the WHERE clause, I filter out the nulls.
0
Rex85Author Commented:
mbizup: I believe your assessment is correct. I can find dates with no data (nulls) by joining the dates with data table to the possible dates table, but that returns one null per date with no data. The problem is that there are four locations, so I need to do that for each locations, essentially asking a query to tell me what data is NOT there for four different locations at each of the possible dates.
If three plants had no data for a date, but one did, I would need the one plant's data for that date and three nulls for that date, one for each separate location that had no data. It's probably possible, but I am working right now on breaking it out....doing it with a query by plant, rather than one very clever query.
I will try what you have suggested though. I would much rather reduce my queries by 75%.
0
Rex85Author Commented:
Thank you for your help. I really appreciate it.
Rex
0
Question has a verified solution.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
If I'm understanding correcly, the 'missing' records you want have nothing in the Plant field and nothing in the date field, beause there is no data from your main table corresponding to the right-joined data in your "all dates" table.
You might be able to resolve this by revising your plant criteria to allow NULL plants, or maybe a combination of Null Dates and Null plants
Like this:
WHERE ((B_ClosedByWeek_CARs_Tbl.
Or This:
WHERE ((B_ClosedByWeek_CARs_Tbl.