Hi,
This is driving me crazy, but I am sure I am missing something simple. I have built an Access 2007 report that shows 2 rows of sales data from each of a bunch of store locations. My table has the date, the location and the sales_amount. I need to have my report group on locations. The resulting rows include a date and the sales_amount, and I have been able to display the sales_amount for a requested date (through a parameter query) and the sales_amount from the same week in the previous year, and these rows are shown for each location. But I now need to be able to show the $ change in sales_amount and the percent change in sales_amount for each location between the current and previous year. This means that I somehow need to access data from (both of) the grouped rows and calculate and display the results. How do I access data from multiple rows? Do I have to create the report manually using VBA, and if so, any examples out there?
Here is an example of what I am trying to accomplish:
Table Sales has Location, Date and SalesAmount, and records such as:
loc1, 10/10/2007, $40
loc2, 10/10/2007, $40
loc3, 10/10/2007, $60
loc1, 10/10/2008, $50
loc2, 10/10/2008, $30
loc3, 10/10/2008, $70
I want a report that shows:
--- start of report ---
loc1
10/10/2008 $50
10/10/2007 $40
$change = $10 +25%
loc2
10/10/2008 $30
10/10/2007 $40
$change = -$10 -33%
loc2
10/10/2008 $70
10/10/2007 $60
$ change - $10 +17%
----- end of report -----
4 4308 NeoPa 32,556
Expert Mod 16PB
This will need to be done in code. Queries (SQL) have no concept of relative records.
Too close to bedtime, but given your demonstrated format, this code will produce the desired results, but only in a Linear Fashion: - Dim strSQL As String
-
Dim MyDB As DAO.Database
-
Dim rstSales As DAO.Recordset
-
Dim rstClone As DAO.Recordset
-
-
strSQL = "SELECT Sales.Location, Sales.Date, Sales.[Sales Amount] " & _
-
"FROM Sales ORDER BY Sales.Location, Sales.Date DESC;"
-
-
Set MyDB = CurrentDb
-
Set rstSales = MyDB.OpenRecordset(strSQL, dbOpenDynaset)
-
Set rstClone = rstSales.Clone
-
-
rstSales.MoveFirst
-
rstClone.MoveFirst
-
rstClone.Move 1 'Move to the 2nd Record in Clone
-
-
With rstSales
-
Do Until rstClone.EOF
-
If ![Location] = rstClone![Location] Then
-
Debug.Print ![Location] & " | " & ![Date] & " | " & ![Sales Amount] & _
-
" | " & rstClone![Date] & " | " & rstClone![Sales Amount] & " | " & _
-
Format$(![Sales Amount] - rstClone![Sales Amount], "Currency") & _
-
" | " & Format$((![Sales Amount] - rstClone![Sales Amount]) / ![Sales Amount], "Percent")
-
End If
-
rstClone.MoveNext
-
.MoveNext
-
Loop
-
End With
-
-
rstSales.Close
-
rstClone.Close
-
Set rstSales = Nothing
-
Set rstClone = Nothing
OUTPUT: - loc1 | 10/10/2008 | 50 | 10/10/2007 | 40 | $10.00 | 20.00%
-
loc2 | 10/10/2008 | 30 | 10/10/2007 | 40 | ($10.00) | -33.33%
-
loc3 | 10/10/2008 | 70 | 10/10/2007 | 60 | $10.00 | 14.29%
NOTE: Any questions, feel free to ask.
Thank you very much. So I have to use VBA and create a custom Report, which in hindsight, seems obvious. I will go and get a Access/VBA book and figure out the details, but this has helped me get started.
NeoPa 32,556
Expert Mod 16PB
Sounds like a plan :)
We're here if you need help of course.
Welcome to Bytes!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: rozrabiak |
last post by:
Hi!
How can I get percent of executed procedure in MSSQL Server, lik in
Enterprise Manager and/or dbMgr2k ?
I use Visual C# and MSDE.
Thank's for help, gregory
|
by: JohnnyRuin |
last post by:
Hi,
My table has int Field1 and DateTime dtModificationTime. I maintain a
history of changes to the table by inserting a new record with a new
dtModificationTime. I need to be able to find...
|
by: MX1 |
last post by:
Hi all,
I've setup a table with one field that will hold percent values. The type
is number and the format is percent on the field. When I do data entry
directly into the field, I have to put...
|
by: Macbeth |
last post by:
Thanks to All who Help,
I am creating a crosstab querry to place in a report. All my data is
correct and I do not seem to have any problem with this area. I am
having problems with displaying...
|
by: tshad |
last post by:
I have a Datagrid with a column:
<asp:HyperLinkColumn
DataTextField="JobTitle"
DataNavigateUrlField="PositionID"
DataNavigateUrlFormatString="AddNewPositions.aspx?PositionID={0}"...
|
by: VidTheKid |
last post by:
THE PROBLEM
The % symbol is too vague when defining dimensions in CSS and HTML. It
can relate to an inherited value, a measure of the containing element
(which can differ between box models) or...
|
by: prasadjoshi124 |
last post by:
Hi All,
I am writing a small tool which is supposed to fill the filesystem to a
specified percent.
For, that I need to read how much the file system is full in percent,
like the output given...
|
by: nycjay |
last post by:
I am trying to do the following w/ SQL for db2 9...
I want to find the top x percent of rows. For example, if i wanted to
find the average sale price of the top 10 most expensive items in a
store,...
|
by: Bernice J |
last post by:
I have a table with four fields: BlockNo, District, SubDate, Status. I would like to create a report that 1)shows the percent of BlockNo that has a SubDate(IsNotNull) grouped by District and 2) shows...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |