473,405 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Delta Column in access 2007

Tabasco
25
Hello bytes,
Im playing around abit with graphs in access 2007 and i would need to visualise the diffrence rather then the total;

for example if the total if 100 year one, 120 year two and 150 year three i would like the graph to be ,(1,0) (2,20) (3,30). Scince the graphs are based on quaries i though it would be simple to add a delta column but I find it easier said than done and im stuck.

So what am I trying to do, Im trying to create a column which get the value from its row and subract it with the value from the row before (except the first year which need to be 0)

heres the sql statement i got so far
Expand|Select|Wrap|Line Numbers
  1. SELECT PrivatePropertyMarketMDB.Statistic AS SQLSMÅHUS, PrivatePropertyMarketMDB.PubDate, MunicipalityMDB.Municipality, MunicipalityMDB.MunicipalityCode
  2. FROM MunicipalityMDB INNER JOIN (DevelopmentTypeMDB INNER JOIN PrivatePropertyMarketMDB ON DevelopmentTypeMDB.DevType_id = PrivatePropertyMarketMDB.DevelopmentType) ON MunicipalityMDB.Municipality_ID = PrivatePropertyMarketMDB.Municipality
  3. WHERE (((DevelopmentTypeMDB.DevelopmentType)="småhus"));
  4.  
If anyone have any tip of what to do or know any article which could help i would be grateful!
Feb 14 '13 #1
9 2067
Rabbit
12,516 Expert Mod 8TB
I can't comment too much on your SQL because you haven't told us what your table design looks like but I can offer general advice.

You will need to join the table to itself so that you can get the previous year's data so that you can calculate the delta. It will have to be an outer join because the first year will not have a previous year to join to. You will need to handle the resulting Null using the Nz function.
Feb 14 '13 #2
NeoPa
32,556 Expert Mod 16PB
Tabasco:
Scince the graphs are based on quaries i though it would be simple to add a delta column but I find it easier said than done and im stuck.
That would be wrong thinking indeed. Database work is all based on Set Theory. There is no concept of juxtaposition (or relative order) within Set Theory. That's a way of thinking you would benefit greatly from leaving behind.
Feb 15 '13 #3
Rabbit
12,516 Expert Mod 8TB
@NeoPa, well, I don't know about leaving it behind. Perhaps leave behind the idea of it being easy to compare between records in SQL. But not leaving behind the idea of ever comparing between records in SQL.

If the requirement the customer wants is to graph the deltas, I don't know how they would feel about hearing that they shouldn't because it's not in line with set theory.
Feb 15 '13 #4
NeoPa
32,556 Expert Mod 16PB
Indeed. I believe I was quite specific in referring to the way of thinking though.

As you so correctly imply, many things can be achieved in Access, even if they are conceptually foreign to the whole concept of RDBMSs. I do believe though, that the whole way of thinking (that can probably be best explained by thinking of Access as Excel) is quite detrimental to doing work within an RDBMS (of any variety). This thinking (to my mind at least) was illustrated quite clearly in the short excerpt I quoted in my post.

Letting go of that would certainly be of great benefit to the OP (Like leaving behind a ruck-sack full of bricks on a hike). Until they do let go, it will only weigh them down.
Feb 15 '13 #5
Tabasco
25
Thank you both for the useful and insightful tip,
I got it working evantually and I'll write the code if someone else hase the same problem of course you cant copy it but it might serve as a step in the wright direction
Expand|Select|Wrap|Line Numbers
  1. SELECT t2.date AS Expr1, t2.TABLE-t1.TABLE AS Delta,
  2. FROM [TABLE] AS t2 INNER JOIN [TABLE] AS t1 ON t2
  3. WHERE (((t2.date)=DateAdd("yyyy",1,[t1].[pubdate])));
  4.  
The access graph tool visualize the SQL statement so I have to get a SQL to show delta because im trying to avoid Excel completely. It much more simple to use excel to get the deltacolumn however it wast so hard in access either once I knew how to do it.


Thanks again for the help!
Feb 15 '13 #6
Rabbit
12,516 Expert Mod 8TB
I noticed you used an inner join instead of the outer join I suggested. Do you not need the first year? If you do, you'll have to use an outer join.
Feb 15 '13 #7
Tabasco
25
Yes i need the first entry and, i tried to use outer join directly in the first sqlstatement but it didnt work, in access you seem to have to use "FULL OUTER JOIN", "LEFT OUTER JOIN" and "RIGHT OUTER JOIN" I tried all three but it seems not to give the result i need.

However i use it later because i also have a sqlstatement which calculate the total for evervy entry (So i get every row) so I join this statement whith the other statement with an outerjoin, I just posted the sqlstatement for which i got the deltacolumn.

But I works kind of slow maybe it will be faster if I'm able to use the outer join directly?

PS I used IIF(ISNULL(DELTA); DELTA; 0) mainly because of old habits instead of NZ() function maybe thats slowing it down DS
Feb 16 '13 #8
Rabbit
12,516 Expert Mod 8TB
You have to use a left outer join. And your where condition needs to be in the join. You can use the IIF or the NZ, I doubt if one will be significantly faster than the other. NZ is probably only slightly faster.
Feb 16 '13 #9
NeoPa
32,556 Expert Mod 16PB
Rabbit:
your where condition needs to be in the join
Further to Rabbit's comment - the ON section of the JOIN needs to be specified to select the required records only. Your code :
Expand|Select|Wrap|Line Numbers
  1. FROM [TABLE] AS t2 INNER JOIN [TABLE] AS t1 ON t2
... is incorrectly formatted. I don't even know how it worked, but I expect it simply treats it as TRUE. This would produce a Cartesian Product (At this point see SQL JOINs.) which makes sense when using a WHERE clause, but would be expected to run relatively slowly.

Instead of using this particular WHERE clause, you should specify the logic using ON, such as :
Expand|Select|Wrap|Line Numbers
  1. SELECT t1.Date
  2.      , t1.Table-t2.Table AS Delta
  3. FROM   [TABLE] AS t1 LEFT JOIN [TABLE] AS t2
  4.   ON   t1.Date=DateAdd('yyyy',1,t2.PubDate)
Having now looked at your SQL in more detail it is clear that it has never run as you posted it. It had some serious syntactical errors in it that no SQL engine could run.

You should also be aware that, as a function is integrally involved in the selection of records, this SQL will run slower than if that were not the case. Faster than the same code in the WHERE clause hopefully, but nevertheless not top speed for SQL. I don't see a way of avoiding this. Even if each record represents a separate year there would still be some level of function call required to determine which records matched which.
Feb 17 '13 #10

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

Similar topics

1
by: Eugene | last post by:
Hello All, I need a report in Access 2007 to show a dynamic image on every page. I have a table, and I store image's path in a cell in each of the rows. In 2003, I was able to do that using...
7
by: ARC | last post by:
This is taken from the "What's New in Access 2007" page. However, I've looked through all the properties of a text field memo box, and cannot find the append only option. Does anyone know how to...
1
by: Kev | last post by:
Hello, Can someone tell me if Access 2007 can wrap the datasheet column heading like Excel does? I know I can do it in continuous form view but I would prefer to use a datasheet. Am wondering...
9
by: haniss | last post by:
After importing a txt delimited file into Access 2007 with adding Couonter there is a problem with column order. For example in txt file: John|Doe|25.10.2007 in new Access table are 4...
9
by: anthony | last post by:
In Access 2007, why does a query field designed as Term: ! ! return 00:00:00 when cboTerm actually contains 08SP. This works as expected in Access 2003?
2
by: curran.george | last post by:
'add one textbox to form1 with Control Source property = ID 'copy/paste the form_load code below: 'Then open the form and then attempt to sort the datasheet 'crashes 2003, error 3450 Access 2007 -...
9
by: prakashwadhwani | last post by:
Hi !! I'm about to develop a new project for a client. Should I go about it in Access 2003 or 2007 ? Purchasing it either for me or for my client is not a major consideration here ... what I'd...
3
by: khoward | last post by:
Hi, I have an Access 2007 database that contains customer contact information. There are over 8,000 that include name, organization (as a look-up column), email, phone, address, and events that...
2
by: Lina Arraiz | last post by:
First of all, my apologies for originally posting this question in the wrong section. I'm trying to export an Excel 2003 spreadsheet to Access 2007. Column D (START) has the start time and Column E...
0
by: prashantdixit | last post by:
Hi, I have beent trying importing Excel data with one column containing PDF/JPEG file name to access 2007. I have a Excel file with few columns One of the columns named as "Reference". The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.