473,569 Members | 2,901 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access - Crosstab Query Performance

1 New Member
Hi,
I have finally been converted to Access as the data set I’m using grew to a ridiculous size. I am analysing one years’ worth of data and the database itself has grown to be quite large at just over 1GB with a few million rows number of rows. This looks at about 700 stations and for each stations there are many 10,000’s of rows of data, hence the need to switch to a database.

I then also have an excel spreadsheet that contains some reference data for each station that we intend to update over time, hence why I wanted to keep it separate.

My question is regarding performance of the database in general. I am running cross tab queries that can take in excess of 20+minutes to run. If this is normal for a data set of this size then I will have to live with it but if not I would appreciate any suggestions on how to speed things up.

I created a query that combines the two data sets, the raw data and the station key using a relationship, the code of which I have shown below, and this runs relatively quickly (<5 seconds) which was quite encouraging.
Linked Data Query:

Expand|Select|Wrap|Line Numbers
  1. SELECT [2013 Data Private].Hour
  2.    , [2013 Data Private].Dte
  3.    , [2013 Data Private].Unidad
  4.    , [2013 Data Private].[Type Offer]
  5.    , [2013 Data Private].Volume
  6.    , [2013 Data Private].Price
  7.    , [2013 Data Private].OM
  8.    , [Linked MIBEL Codes].Type
  9. FROM [Linked MIBEL Codes] 
  10.    INNER JOIN [2013 Data Private] 
  11.       ON [Linked MIBEL Codes].[UP Code] 
  12.          = [2013 Data Private].Unidad
  13. WHERE ((
  14.    ([2013 Data Private].[Type Offer])="v") 
  15.       AND (([2013 Data Private].OM)="O"));
I then built another query off the first (this is the start of many layers) to be able to quickly filter the data under certain criteria, one query being built to filter price in a range of a min, mid and max scenario. Code again shown below for the min filter (one of three) and whilst performance was worse (<10 seconds) I was still happy with this. Admittedly the code does not look good from below but the purpose of the query is to filter by the 14 station types, each with a different price. As I said I think this part works fine in most but for reference purposes

Expand|Select|Wrap|Line Numbers
  1. SELECT [2013 Data Private].Hour
  2.    , [2013 Data Private].Dte
  3.    , [2013 Data Private].Unidad
  4.    , [2013 Data Private].[Type Offer]
  5.    , [2013 Data Private].Volume, [2013 Data Private].Price
  6.    , [2013 Data Private].OM
  7.    , [Linked MIBEL Codes].Type
  8. FROM [Linked MIBEL Codes] 
  9.    INNER JOIN [2013 Data Private] 
  10.       ON [Linked MIBEL Codes].[UP Code] 
  11.          = [2013 Data Private].Unidad
  12. WHERE ((
  13.    ([2013 Data Private].[Type Offer])="v") 
  14.       AND (([2013 Data Private].Price)<15) 
  15.       AND (([2013 Data Private].OM)="O") 
  16.       AND (([Linked MIBEL Codes].Type)="COAL")) 
  17.    OR ((([2013 Data Private].[Type Offer])="v") 
  18.       AND (([2013 Data Private].Price)<30) 
  19.       AND (([2013 Data Private].OM)="O") 
  20.       AND (([Linked MIBEL Codes].Type)="GAS")) 
  21.    OR ((([2013 Data Private].[Type Offer])="v") 
  22.       AND (([2013 Data Private].Price)<50) 
  23.       AND (([2013 Data Private].OM)="O") 
  24.       AND (([Linked MIBEL Codes].Type)="OIL")) 
  25.    OR ((([2013 Data Private].[Type Offer])="v") 
  26.       AND (([2013 Data Private].Price)<5) 
  27.       AND (([2013 Data Private].OM)="O") 
  28.       AND (([Linked MIBEL Codes].Type)="NUKE")) 
  29.    OR ((([2013 Data Private].[Type Offer])="v") 
  30.       AND (([2013 Data Private].Price)<30) 
  31.       AND (([2013 Data Private].OM)="O") 
  32.       AND (([Linked MIBEL Codes].Type)="Thermal")) 
  33.    OR ((([2013 Data Private].[Type Offer])="v") 
  34.       AND (([2013 Data Private].Price)<15) 
  35.       AND (([2013 Data Private].OM)="O") 
  36.       AND (([Linked MIBEL Codes].Type)="Dom Coal")) 
  37.    OR ((([2013 Data Private].[Type Offer])="v") 
  38.       AND (([2013 Data Private].Price)<5) 
  39.       AND (([2013 Data Private].OM)="O") 
  40.       AND (([Linked MIBEL Codes].Type)="Geothermal")) 
  41.    OR ((([2013 Data Private].[Type Offer])="v") 
  42.       AND (([2013 Data Private].Price)<5) 
  43.       AND (([2013 Data Private].OM)="O") 
  44.       AND (([Linked MIBEL Codes].Type)="Pumping Stor.")) 
  45.    OR ((([2013 Data Private].[Type Offer])="v") 
  46.       AND (([2013 Data Private].Price)<5) 
  47.       AND (([2013 Data Private].OM)="O") 
  48.       AND (([Linked MIBEL Codes].Type)="Hydro")) 
  49.    OR ((([2013 Data Private].[Type Offer])="v") 
  50.       AND (([2013 Data Private].Price)<15) 
  51.       AND (([2013 Data Private].OM)="O") 
  52.       AND (([Linked MIBEL Codes].Type)="N/a")) 
  53.    OR ((([2013 Data Private].[Type Offer])="v") 
  54.       AND (([2013 Data Private].Price)<5) 
  55.       AND (([2013 Data Private].OM)="O") 
  56.       AND (([Linked MIBEL Codes].Type)="Solar PV")) 
  57.    OR ((([2013 Data Private].[Type Offer])="v") 
  58.       AND (([2013 Data Private].Price)<5) 
  59.       AND (([2013 Data Private].OM)="O") 
  60.       AND (([Linked MIBEL Codes].Type)="Solar Ther.")) 
  61.    OR ((([2013 Data Private].[Type Offer])="v") 
  62.       AND (([2013 Data Private].Price)<5) 
  63.       AND (([2013 Data Private].OM)="O") 
  64.       AND (([Linked MIBEL Codes].Type)="Wind")) 
  65.    OR ((([2013 Data Private].[Type Offer])="v") 
  66.       AND (([2013 Data Private].Price)<15) 
  67.       AND (([2013 Data Private].OM)="O") 
  68.       AND (([Linked MIBEL Codes].Type)="UNKNOWN"));
However the problem comes when I begin to build cross tab queries off this final query which contains the filtered results. The first is a simple average of prices across months however this now takes 5 minutes to run on its own for me to be able to get a table that can be exported to excel. In addition I would love for the cross tab query to show a weighted average of price instead of the simple average it does now.
Average Price Crosstab Query:

Expand|Select|Wrap|Line Numbers
  1. TRANSFORM 
  2.    Avg([Price Development Volume Query Min].Price) 
  3.          AS AvgOfPrice
  4.    SELECT [Price Development Volume Query Min].Type
  5.       , [Price Development Volume Query Min].Unidad
  6.       , Avg([Price Development Volume Query Min].Price) 
  7.          AS [Total Of Price]
  8. FROM [Price Development Volume Query Min]
  9. GROUP BY [Price Development Volume Query Min].Type
  10.       , [Price Development Volume Query Min].Unidad
  11. PIVOT Format([Dte],"mmm") 
  12.    In
  13.    ("Jan","Feb","Mrz","Apr"
  14.       ,"Mai","Jun","Jul","Aug"
  15.       ,"Sep","Okt","Nov","Dez");
The final cross tab query is supposed to simply sum up the total volume offered in each hour, for each day and for each station. Whilst I fully appreciate this gives a v.large data set the query takes in excess of 20 minutes to run and often causes access to crash.
Volume Crosstab Query:

Expand|Select|Wrap|Line Numbers
  1. TRANSFORM 
  2.    Sum([Price Development Volume Query Min].Volume) 
  3.       AS [Volume]
  4.    SELECT [Price Development Volume Query Min].Type
  5.       , [Price Development Volume Query Min].Unidad
  6.       , [Price Development Volume Query Min].Date
  7. FROM [Price Development Volume Query Min]
  8. GROUP BY [Price Development Volume Query Min].Type
  9.       , [Price Development Volume Query Min].Unidad
  10.       , [Price Development Volume Query Min].Date
  11. PIVOT [Price Development Volume Query Min].Hour;
Any feedback on how to improve performance, if only slightly, would be greatly appreciated. Am fully expecting that I have built in a lot of excess that has potential to be stripped out
Mar 31 '14 #1
1 2037
Stewart Ross
2,545 Recognized Expert Moderator Specialist
A downside of crosstabs is that Access does not know even what fields it is going to have as a result of the Transform statement until it completely evaluates the underlying Select statement. Having done that, Access then has to sort out the summing and so on under the columns concerned. This can take a considerable amount of time to do, as you are finding.

One factor in your SQL which will cause a deterioration in performance is that you have a complex WHERE clause with multiple text comparisons such as

Expand|Select|Wrap|Line Numbers
  1. ([2013 Data Private].[Type Offer])="v") 
  2.        AND (([2013 Data Private].Price)<15) 
  3.        AND (([2013 Data Private].OM)="O") 
  4.        AND (([Linked MIBEL Codes].Type)="COAL"))
I would suggest simplifying or eliminating these as much as possible, as text comparisons take many times longer to execute than numeric comparisons, and the complex sets of ANDs and ORs will not help this process.

Similarly, GROUP BY statements based on text fields are more time consuming to execute than those based on simpler numeric fields, so if you have numeric code alternatives for your text values you may wish to group on those instead.

Even your Pivot statement is based on a text conversion - from date to a month name - which will also cause a performance hit when compared to pivoting on a month number (such as month([dte]) in place of your format([dte], "mmm")).

Bear in mind as I mentioned that Access cannot even know the names of all the fields resulting from the Transform statement until all the underlying SQL has been executed across all rows of all parts of the underlying SQL, so comparing the performance of a crosstab to its underlying Select statements is not going to give a true picture of what is efficient and what is not.

One final piece of advice is never feed a crosstab into another crosstab. I'm not sure that you are, but if you are I would keep any queries on which you base the final crosstab as SELECT statements with no crosstabbing. Access can really struggle if one crosstab feeds another.

-Stewart
Mar 31 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
8106
by: Judy | last post by:
I'm using Access 2003 and was wondering if it is possible to have a paramater selection within a crosstab query so that I wouldn't need to build a new table. I have a select query that I'm using to build the crosstab query from. In the select query I'm prompting for a specific quarter but when I go to run the crosstab it doesn't seem to...
2
3198
by: Greg Busby | last post by:
I'm trying to get an Access Crosstab query to fill a VB.NET datagrid. I'm getting an error that states "not a valid file name".. the query runs fine when I run the same SQL in Access. Can a dataAdapter be filled with data from a crosstab query
14
3477
by: Tina | last post by:
My employer tracks productivity/performance of clinicians (how much they bill) each week, its averages for the month, and the 6 months. These averages are compared to their expected productivity. However, the expectation changes - it may be 60% for a while, then change to 50%. Initially, I was averaging the expectation, along with the...
6
4448
by: tizmagik | last post by:
I am having a lot of difficulty generating a CrossTab Query based report. I have looked online for several tutorials and whatnot but I have not been able to really find what I'm looking for, nor have I been able to adapt other people's solutions/tips to fit what I need. If anyone could please help me with the following it would be really...
2
3344
by: Mike | last post by:
Hi everyone, I found the Access reports too limited to do what i wanted so i created a module to export a crosstab query to an excel file, and then i modify it as i want. My problem is that i created a unique query for every "sector", saved them, and select the right one according to the user's choice. What i'd like to do is to create...
3
6589
by: russellhq | last post by:
Hi, I'm fairly new to access and have a little trouble with a crosstab query I've setup. I have a main form where the user selects a project name and below in a subform, a crosstab query is displayed in a datasheet view. The info is dependant on the project picked. What I tried to do is set the criteria in the the query to only show results...
4
2482
by: rdsandy | last post by:
Hi, I have some code below in VBA for Access 2003 which is on a button called "RentalCrosstabPercTtlQtyMonthLoc_Click". This is a crosstab query which brings up rental items down the side, who rents along the top, the rental month and total number of each item on that month as rows next to the item, something like this: Item TotalQty ...
8
5901
by: Paul H | last post by:
I want to base a form on a crosstab query. The query shows statistics for a user defined period. The column headings will look something like this: ClientID Month01 Month02 Month03 etc.. So if the user selects 3 months in the criteria form, there will be 3 (month) column headings, if he selects 6 months, the will be 6 headings.
2
3394
by: Jim Devenish | last post by:
I wish to create a crosstab query as the record source for a report. It needs to count data between selected dates which are entered by the user in a popup window. The following Select query works: SELECT Tasks.EnquirySourceID, Tasks.BusinessUnitID, Count(Tasks.TaskID) AS CountOfTaskID FROM Tasks WHERE (((Tasks.TaskDate)>=!!)) GROUP BY...
0
7917
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7665
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6277
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
933
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.