Access - Query with Cumulative Field - Performance question

This is a follow on question to my earlier question today about creating a Cumulative Amt Field in a Query where I needed it to include all [Shifts] and all [TransTypeID]'s even if a subsequent Shift's reporting doesn't include a particular TransTypeID that was used in an earlier [Shift] on the business day.

My question now is the performance of that query.  Based upon how I have it, it churns for about 20-30 seconds before I get results and this is with my limited number of records thus far.

I am attaching the DB.  The query in question is [qry_XCumul].  

Since I want all TransTypes possible to be included I created a Cartesian qry for Shifts and TransTypes.... that query is [qry_AllTransTypeAllShifts]

I suspect that the issue is in my Cumulative calculation using DSum
the code is
SELECT qry_X.ShiftID, qry_X.BusDay, qry_X.TransTypeID, Val(nz(DSum("Amt","qry_X","ShiftID<=" & [qry_x].[ShiftID] & " AND TransTypeID=" & [qry_x].[TransTypeID] & " AND BusDay=#" & [qry_x].[BusDay] & "#"),0)) AS CumulAmt
FROM qry_X
GROUP BY qry_X.ShiftID, qry_X.BusDay, qry_X.TransTypeID, Val(nz(DSum("Amt","qry_X","ShiftID<=" & [qry_x].[ShiftID] & " AND TransTypeID=" & [qry_x].[TransTypeID] & " AND BusDay=#" & [qry_x].[BusDay] & "#"),0));

Open in new window


So, Is there a better way (ie: faster processing) that I could write that query???? Or would it be based on the fact that I have a Cartesian query being:
SELECT tblCtl_Shifts.ShiftID, tblCtl_Shifts.BusDay, sCtl_TransType.TransTypeID, sCtl_TransType.TransType
FROM tblCtl_Shifts, sCtl_TransType;

Open in new window


My qry_X code which the Cumulative query is based on is: (in case you don't want to open the DB....
SELECT qry_AllTransTypeAllShifts.ShiftID, qry_AllTransTypeAllShifts.BusDay, qry_AllTransTypeAllShifts.TransTypeID, Val(nz(Sum([LineItemNoTx]),0)) AS Amt, Val(nz(Sum([CSTax]),0)) AS TTx
FROM ((qry_AllTransTypeAllShifts LEFT JOIN (tbl_OtherPdOuts RIGHT JOIN tbl_CashFundActivityNoDenom ON tbl_OtherPdOuts.CashFdActNoDenomID=tbl_CashFundActivityNoDenom.CashFdActNoDenomID) ON (qry_AllTransTypeAllShifts.TransTypeID=tbl_CashFundActivityNoDenom.TransTypeID) AND (qry_AllTransTypeAllShifts.ShiftID=tbl_CashFundActivityNoDenom.ShiftID)) INNER JOIN sCtl_TransType ON qry_AllTransTypeAllShifts.TransTypeID=sCtl_TransType.TransTypeID) LEFT JOIN tbl_OtherPdOutsDetails ON tbl_OtherPdOuts.OtherPdOutsID=tbl_OtherPdOutsDetails.OtherPdOutsID
GROUP BY qry_AllTransTypeAllShifts.ShiftID, qry_AllTransTypeAllShifts.BusDay, qry_AllTransTypeAllShifts.TransTypeID;

Open in new window


THANK YOU IN ADVANCE for the suggestions!
Cumulative-TransType-By-Day.accdb
wlwebbAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nick67Commented:
Any of the Domain Aggregate functions are performance killers to be avoided whenever possible.  ESPECIALLY in the WHERE clause.
You are already using query results in the subsequent query from the look of things.  Can you not create queries that will avoid the use of such things?
Cartesian queries are performance killers as well.
I have one query that is actually the cascaded result of 4 queries.
It runs well.

I can't open an accdb here as I run Access 2003.
I may have a gander later on A2010

Are you adverse to having this done with VBA, and not in queries?
0
PatHartmanCommented:
The Cartesian product I recommended in the other thread will be slow for more than a few dozen records.  But before blaming that I would get rid of the domain functions.  In all cases, you can create totals queries to replace the domain functions and then join to the totals query.  This allows the query engine to optimize the query.  Domain functions will run a separate query for each row so if the query is returning a thousand rows, it is running the domain function query a thousand times.  That is a lot of overhead.
0
wlwebbAuthor Commented:
Pat
To clarify .... Are you saying to first run a query that totals or Sums each Shifts data and then after that query have another query that joins as Cartesian to TransTypeIDs ???
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

wlwebbAuthor Commented:
Nick
Can you not create queries that will avoid the use of such things?

Thank you for your input.  The reason that I'm doing the query is this.  The results are used in reporting on a form and in a report not only that certain Shift's info but also for the entire selected business day through the end of that certain Shift.  The problem I had is that every shift doesn't have all TransTypeID's in their Shift's Data.  However, to report a Day-to-ShiftEnd column for Shift 2 of the day or Shift 3 of the day etc, if for example SHift 1 had a TransType 5 but Shift 2 or 3 didn't then Somehow I have to get a total of TransType 5 I need the Cumulative Amount of all TransType 5s from the Prior Shift.

I have saved this stripped down DB as a A2002-03 version and attached for your conveienence if you want to see.
Cumulative-TransType-By-Day-A2002-03-Ver
0
bonjour-autCommented:
hi wlwebb

just change the queries as shown in the attachment to get rid of the domain functions.
0
wlwebbAuthor Commented:
bonjour-aut

No attachment....
0
bonjour-autCommented:
just for the case the upload does not work:

change qry_X to:

SELECT qry_X.ShiftID, qry_X.BusDay, qry_X.TransTypeID
FROM qry_X
GROUP BY qry_X.ShiftID, qry_X.BusDay, qry_X.TransTypeID;

Open in new window


and qry_XCumul to:

SELECT qry_AllTransTypeAllShifts.ShiftID, qry_AllTransTypeAllShifts.BusDay, qry_AllTransTypeAllShifts.TransTypeID, qry_X2.Amt, qry_X2.TTx
FROM qry_AllTransTypeAllShifts LEFT JOIN qry_X2 ON (qry_AllTransTypeAllShifts.BusDay = qry_X2.BusDay) AND (qry_AllTransTypeAllShifts.TransTypeID = qry_X2.TransTypeID);

Open in new window

0
bonjour-autCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wlwebbAuthor Commented:
bonjour-aut.
Copy and pasted .... get following

I'm getting "Circular Reference" when I changed qry_X

Then on qry_XCumul I get the error MS engine cannot find the input table or query 'qry_X2.
0
wlwebbAuthor Commented:
Just got the upload bonjour-aut.... looking at now....


I assume I dont need the Module for Date and Time Zones.....
0
wlwebbAuthor Commented:
MUCH faster than my version!!!!!!  Thank you... Now I'll try to apply that theory to mine to see if I can understand and get it to work when I do it....

Thank you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.