Question : How To Transpose A Access 2007 Query Result

I have a simple select query that selects 6 columns: Year, TotalSales, ProductCost, AdminCost, Salary, Profit (see first part of attached image).   I need to transpose the query results such that each column appears as a row (see second part of image).  Question:  Can this be done in a single query?  I need to use the query in a Visual Basic .net 2008 application to populate a DataGridView data table.  

Answer : How To Transpose A Access 2007 Query Result

You need to create a temporary table that normalizes the data with these columns:

Year (2005, 2006, etc.)
Data Category (Total Sales, Product, etc.)
Amount

Then you run a crosstab on the table with the year as you Column Heading, Data Category as your Row Heading, and Amount as your Value field using Sum. If you want to order the Data Category, create another table with the list of values and their sort order and link on that in the crosstab query sorting on the sort order field.

The code to normalize your data would be pretty simple to write. If that's too much, consider our Total Access Statistics program which has a data normalization feature optimized to manage a large number of records and options. More info here: http://www.fmsinc.com/MicrosoftAccess/StatisticalAnalysis.html

Good luck.

Random Solutions  
 
programming4us programming4us