Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Help calculating differences in values based on Date in Access Upd

Posted on 2014-03-31
8
Medium Priority
?
316 Views
Last Modified: 2014-04-01
Hello EE,

I raised a question on how to calculate the difference in values based on Date in Access.  Please refer to the posting here - http://www.experts-exchange.com/Database/MS_Access/Q_28371877.html I received an answer that worked but when applied to about 50,000 records, the query was extremely slow.  Can someone please help examine the code and help streamline the process?  My data is attached to this question - http://www.experts-exchange.com/Database/MS_Access/Q_28371877.html

Thanks in advance for your help
0
Comment
Question by:fb1990
[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
  • 3
  • 2
  • 2
8 Comments
 
LVL 39

Expert Comment

by:PatHartman
ID: 39967883
Correlated subqueries tend to be slow.  If you can do this calculation in a report it will be significantly faster because you won't need to run a sub query for EVERY row of the main query.  Instead you just refer back to the previous row.

Additionally, try adding a non-unique index on the date field.  That will help the subquery get to the correct record.
0
 
LVL 1

Author Comment

by:fb1990
ID: 39968131
Thanks Pat as always.  Can show me by way of example how your suggestion can be implemented?
0
 
LVL 52

Accepted Solution

by:
Gustav Brock earned 2000 total points
ID: 39968749
You can use a helper-query to find the dates, then use this in another query to find the differences. Demo attached.

/gustav
SampleDiff.mdb
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 39

Expert Comment

by:PatHartman
ID: 39969439
Start by adding an index to the date field to see if that helps.  If it doesn't, remove the index.  No sense having it if it isn't going to help.

To calculate in a report, create two global variables.  Use the Print event to save the current "ID" and value.  Use the Format event to compare to the ID saved by the Print event and calculate the difference.

The thing you need to worry about in a report when you are doing this type of processing is that the Format event might run more than once (if the current record won't fit on the page, Access has to back up and print the page headers, etc and then reprint the detail line) and so can double up on calculations.  Saving the "current" values in Print should eliminate this problem as long as you don't have any running totals.   The Print event has a PrintCount argument so you can always tell that the event has run before if you need to know that.  The Repeat event only runs when Access determines that it can't print the current record because it won't fit on the page.  If you were doing running sums, you would use this event to back out the amounts for the current record so they can be added again in the Format event.
0
 
LVL 1

Author Comment

by:fb1990
ID: 39969490
Pat, Thanks for the suggestions.
0
 
LVL 1

Author Closing Comment

by:fb1990
ID: 39969484
Thank you so much or should i say Tak så meget.  The solution produced my result in a mini fraction of my original process
0
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 39969633
You are welcome!

/gustav
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

604 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