Crosstab with multiple data

D

DIH

Hi all,

O.K. I need to create a report to show multiple pieces of data. I would
guess a crosstab query is needed (but I'm not totally sure). Here is the
way I would need the data to look (in reality there are actually about
20 fields):

11/1/2008 11/2/2008 11/3/2008 11/4/2008 11/5/2008
Weight 2 2.2 2.1 3.1 2.5
Size 6 7 7 7.1 6.8
Stretch 0.01 0.02 0.015 0.03 0.017
Bulk 40 40.5 40.2 39.8 38.9
Grade 10.8 10.9 10.8 10.7 10.5

For simplicity sake, let's say that all the data is stored in a single
table (we'll call it tblData). The table fields are:

AuditDate (which is needed as the column in the crosstab)
Weight
Size
Stretch
Bulk
Grade

Any help is greatly appreciated.

Dave
 
K

Ken Sheridan

You should be able to do this entirely in the report by sing a multi-column
report with 'across then down' column layout. Create a normal query which
returns the necessary columns and base the report on this. Put all the bound
controls in the far left of the detail section in a single column.

In report design view, in the page setup dialogue set the number of columns
to 20 (or whatever), the column spacing and column width as appropriate,
uncheck the 'same as detail' check box and select 'across then down' as the
column layout.

One further consideration is whether all dates will be represented in the
table, and if not, do you want any missing days to show just the date, with
the other controls below empty? If so you'd need to create an auxiliary
Calendar table. This is just a table of all dates over a period, 10 years
say. A simple way to create one is to serially fill down a column in Excel
and import it into Access as a table. You'd then base the report on a query
which joins the tables in an outer join and returns this date column from the
Calendar table in place of the date column from your current table. You can
include parameters to restrict the dates returned to those in a range entered
when prompted at runtime, so the query would be along these lines:

PARAMETERS [Start date:] DATETIME, [End date:] DATETIME;
SELECT [caldate], [weight], [size], [stretch], [bulk], [grade]
FROM [Calendar] LEFT JOIN [YourTable]
ON [Calendar].[caldate] = [YourTable].[yourDateField]
WHERE [calDate] BETWEEN [Start date:] AND [End date:]

Note that date parameters should always be declared to avoid the risk of a
parameter value entered in short date format being misinterpreted as an
arithmetical expression and giving the wrong results.

The advantage of this approach over a crosstab is that the date 'column
headings' are values in a column returned by the query, so there is no need
to dynamically set the ControlSource properties in the report at runtime to
the date values used as the column headings by a crosstab query.

If there is other data you want returned only once per set of dates then the
multi-column report can be inserted as a sub-report in a parent report. You
can find an example of this at:


http://community.netscape.com/n/pfx...libraryMessages&webtag=ws-msdevapps&tid=24271


This differs from yours in that there is only one row per column, wrapping
to a second row when the last column is reached, but the principle is much
the same. The file was originally produced in response to a readers request
in a magazine column by a contact of mine, and also contains a single report
solution in which the layout is amended in code at runtime, but that was only
included to show that its possible, not suggested as a serious solution, for
which a multi-column subreport is far simpler.

Ken Sheridan
Stafford, England
 
Top