Step 0_1 would be to get all date:
SELECT planneddate+1-DatePart("d",planneddate) AS myMonths FROM
qryMaintbl
UNION
SELECT testingdate +1-DatePart("d",testingdate ) FROM qryTestingTbl
I am not sure about the last SELECT, it should involves the table/query
supplying the second set of dates, and the field.
Step 0_2 would be to enter missing dates into qryMaintbl:
SELECT query0_1.myMonths, planned, dir
FROM query0_1 LEFT JOIN qryMaintbl
ON query0_1.myMonths = qryMaintbl.myMonths
Step 0_3 would be to enter missing dates in qryTestingTbl (or whatever)
Steps 1
SELECT planneddate+1-DatePart("d",planneddate) AS myMonths,
Count(planned) AS Planned,
dir
FROM query0_1
WHERE (((query0_1.dir) Like [Enter Directorate]))
GROUP BY planneddate+1-DatePart("d",planneddate), query0_1.dir;
and 2, as actual
Step 3, not usefull anymore, since it is already done at step 0_1 (and
0_2).
Step 4:
SELECT testingplanned.Planned AS Planned,
testingactual.Completed AS Completed,
testingplanned.myMonths, testingplanned.dir
FROM testingplanned INNER JOIN testingactual
ON testingplanned .myMonths = testingactual.myMonths
we don't need the outer join, now, since all the dates ARE in both
tables
(since 0_1 and 0_2)
Hoping it may help,
Vanderghast, Access MVP
I am confused here. so first step I have QSum (for planned) and QSum2
(for
Completed) See Qsum below (for Qsum2 replaced planneddate with
Completed
where appropriate)
SELECT planneddate+1-DatePart("d",planneddate) AS myMonths, Count(*) AS
Planned, qryMaintbl.dir
FROM qryMaintbl
WHERE (((qryMaintbl.dir) Like [Enter Directorate]))
GROUP BY planneddate+1-DatePart("d",planneddate), qryMaintbl.dir;
2nd step
Testingplanned and testingactual queries. See testingplanned below (for
testingactual replaced Planned (or planned ref) with Completed where
appropriate)
SELECT a.myMonths, LAST(a.planned) AS plannedthismonth, SUM(b.planned)
AS
Planned, LAST(a.dir) AS Dir
FROM qSUM AS a INNER JOIN qSum AS b ON a.myMonths>=b.myMonths
GROUP BY a.myMonths
ORDER BY a.myMonths;
3rd Step
alldates union query
SELECT myMonths, dir FROM testingplanned
UNION SELECT myMonths, dir FROM testingactual;
4th Step
Query2
SELECT Nz(testingplanned.Planned,0) AS Planned,
Nz(testingactual.Completed,0) AS Completed, AllDates.myMonths,
AllDates.dir
FROM (AllDates LEFT JOIN testingplanned ON
AllDates.myMonths=testingplanned.myMonths) LEFT JOIN testingactual ON
AllDates.myMonths=testingactual.myMonths;
Where was I to put the code that you provided below.
thanks
Susie
:
Would be easier if you can introduce the (missing) dates BEFORE making
any
sum. In fact, to introduce them as the first step of the whole
process.
Make a first query like:
SELECT allDates.myMonths, Nz(Completed, 0) AS newCompleted
FROM allDates LEFT JOIN yourtable
OIN allDates.myMonths = yourTable.myMonths
This query will so have all the required dates, with an amount of zero
for
the dates that were missing. Now, use THAT query, instead of
'yourtable'
to
make the running sum, in the query that does the said running sum.
Hoping it may help,
Vanderghast, Access MVP
I dont know if I really made clear what my problem was now after
reading
my
post again this morning but where the 0 for completed is for
7/1/2008,
I
really need to see 63 which is the previous months totals brought
forth,
so
my graph will plot correctly. So everywhere this is a 0 or no entry
I
need
the total brought forth so it continues a running sum throughout.
thanks
Susie
:
Thanks so much, I sure appreicate you hanging in there with me. I
have
put
that code into my query and now I just need one more thing. I need
a
line
chart that shows planned versus actual by (cumulative) month so
what I
have
now is:
Planned Completed myMonths dir
21 21 10/1/2007 E
46 47 11/1/2007 E
58 59 12/1/2007 E
61 62 1/1/2008 E
62 63 2/1/2008 E
63 0 7/1/2008 E
64 64 12/1/2008 E
And what I need is:
Planned Completed myMonths dir
21 21 10/1/2007 E
46 47 11/1/2007 E
58 59 12/1/2007 E
61 62 1/1/2008 E
62 63 2/1/2008 E
63 63 7/1/2008 E
64 64 12/1/2008 E
How can I do that?
:
Use Nz on the 'right side' table, like:
SELECT Nz(testingplanned.Planned, 0),
Nz(testingactual.Completed, 0),
AllDates.myMonths,
AllDates.dir
FROM (AllDates LEFT JOIN testingplanned ON AllDates.myMonths =
testingplanned.myMonths) LEFT JOIN testingactual ON
AllDates.myMonths =
testingactual.myMonths;
that will change the NULL to a zero. You can, next, make the
running
sum ( I
am lost at where, which step exactly) we are, but I assume it is
before
making the running sum).
Vanderghast, Access MVP
news:
[email protected]...