?
Solved

Access - Query with Cumulative Field - Performance question

Posted on 2014-12-02
11
Medium Priority
?
186 Views
Last Modified: 2014-12-03
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
0
Comment
Question by:wlwebb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 26

Expert Comment

by:Nick67
ID: 40477603
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
 
LVL 38

Expert Comment

by:PatHartman
ID: 40477881
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
 

Author Comment

by:wlwebb
ID: 40478291
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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

Author Comment

by:wlwebb
ID: 40478377
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
 
LVL 18

Expert Comment

by:bonjour-aut
ID: 40478391
hi wlwebb

just change the queries as shown in the attachment to get rid of the domain functions.
0
 

Author Comment

by:wlwebb
ID: 40478395
bonjour-aut

No attachment....
0
 
LVL 18

Expert Comment

by:bonjour-aut
ID: 40478398
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
 
LVL 18

Accepted Solution

by:
bonjour-aut earned 2000 total points
ID: 40478408
0
 

Author Comment

by:wlwebb
ID: 40478421
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
 

Author Comment

by:wlwebb
ID: 40478439
Just got the upload bonjour-aut.... looking at now....


I assume I dont need the Module for Date and Time Zones.....
0
 

Author Closing Comment

by:wlwebb
ID: 40478451
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

800 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