Transpose Query into new Query

skhaliq

New Member
Joined
Dec 24, 2011
Messages
17
Query View
CodeDistRSMBrand1Brand2Brand3Brand4Brand5Brand6Brand7Brand8Brand9Brand10
320002Ali TradersAsser235678910466

<colgroup><col><col><col><col><col span="8"><col></colgroup><tbody>
</tbody>



Result
CodeDistRSMSKUSales
320002Ali TradersAsserBrand12
320002Ali TradersAsserBrand23
320002Ali TradersAsserBrand35
320002Ali TradersAsserBrand46
320002Ali TradersAsserBrand57
320002Ali TradersAsserBrand68
320002Ali TradersAsserBrand79
320002Ali TradersAsserBrand810
320002Ali TradersAsserBrand94
320002Ali TradersAsserBrand1066

<colgroup><col style="text-align: center;"><col style="text-align: center;"><col style="text-align: center;"><col style="text-align: center;"><col style="text-align: center;"></colgroup><tbody>
</tbody>
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Is the first query a crosstab?
If so, do you just want to group and total the original data?

Denis
 
Upvote 0
If this is a simple "Select" Query, then I believe that you have a normalization issue. You should have your table holding the data set up differently.

TableName
----------
Code (PK)
Dist
RSM
Brand
Data

With your table set up this way, you can run the report as you wish. With your current set up, you will have to run a query for each Brand and then join all of the queries together in a Union Query.
 
Upvote 0
As Alan points out, your data structure is going to cause you trouble.

To create the query using your current data structure, you would need to do something like:
Code:
SELECT Code, Dist, RSM, "Brand1" AS Brand, Brand1 As Amount
UNION
SELECT Code, Dist, RSM, "Brand2" AS Brand, Brand2 As Amount
UNION
SELECT Code, Dist, RSM, "Brand3" AS Brand, Brand3 As Amount
FROM YourTable

... Extending the pattern for all of the brands. When a new brand is added you will need to rewrite / adjust the query to suit.
By using Alan's suggested structure you just need to do the following:
1. Add all fields to the grid
2. Click the big Sigma button to make it a Totals query
3. In the Totals row, change Data from Group By to Sum.

When new brands are added, the query just handles it. No rewriting required.

Denis
 
Upvote 0

Forum statistics

Threads
1,216,116
Messages
6,128,929
Members
449,479
Latest member
nana abanyin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top