Re: Crosstab or Pivot Frustration



"Hansen" <helgardh@xxxxxxxxxxx> wrote in message
news:1193823540.746907.84700@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi

I have one table with the following design:
Fieldname Datatype
Region Text
Supply Number
Sales Number
Revision Number
Refused Number
SoldOut Number

I want to be able to report the data in the following format:
Total Region1 Region2 Region3 Region4
Supply
Sales
Revision
Refused
Soldout

I have been attempting this using crosstab queries and pivot tables to
no avail. I think I don't understand the concept. Can someone please
assis me?

Well, I'll get you started with one approach. There are probably others.
It uses two queries.

The first UNION query restructures you data into a normalized layout:
SELECT Region, "Supply" AS Category, Supply AS Result FROM Table1
UNION
SELECT Region, "Sales" AS Category, Sales AS Result FROM Table1
UNION
SELECT Region, "Revision" AS Category, Revision AS Result FROM Table1
UNION
SELECT Region, "Refused" AS Category, Refused AS Result FROM Table1
UNION
SELECT Region, "SoldOut" AS Category, SoldOut AS Result FROM Table1;


The second CROSSTAB query uses the first query:
TRANSFORM Sum(Result) AS SumOfResult
SELECT Category
FROM Query1
GROUP BY Category
PIVOT Region;

You'll have to do some more work if you want to show "totals".

Fred Zuckerman



.



Relevant Pages

  • Re: UPDATE - UNION
    ... You can change the query as: ... UNION ALL ... SELECT id,col2 as MyAlias, 'Col2' as TargetCol FROM TABLE1 ...
    (microsoft.public.sqlserver.programming)
  • Re: Synching Multiple Tables
    ... pull all the data from all the tables into one master table. ... Do you really need a master table, or can you simply create a UNION query ... FROM Table1 ...
    (microsoft.public.access.replication)
  • Re: Access Query
    ... UNION ALL SELECT * FROM Table3; ... Then the second query does the agregating: ... ANYTHING that would require the use of square brackets, ... FROM [SELECT * FROM Table1 ...
    (microsoft.public.access.formscoding)
  • Re: Criterion - How to Write Query for Multiple Tables
    ... Table1: CoName, Address, WebSite, SalesExec, NULL, NULL, NULL ... The union query is thus: ... > what can be done with the query wizard, ... > simpler way to write a query in Design View to accomplish this task? ...
    (microsoft.public.access.queries)
  • RE: Union Query
    ... A union query won't do it. ... You need to join the various tables with table1. ... Jerry Whittle, Microsoft Access MVP ... The total number of customers is 63,000 ...
    (microsoft.public.access.queries)