Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Desired Format Pivot

Posted on 2013-02-04
10
Medium Priority
?
303 Views
Last Modified: 2013-02-04
Hello ,
Current Format shows the data structure it’s in currently.  Somehow, someway it has to be pivoted to get it in the format I need where time stamp columns transform to the rows instead.  The format I need is shown in Desired Format sheet. The fastest way to o this on 35000-40000 rows
Thanks
pivotDesired.xlsx
0
Comment
Question by:Rayne
  • 4
  • 3
  • 3
10 Comments
 
LVL 24

Assisted Solution

by:Steve
Steve earned 400 total points
ID: 38852607
the following code will do exactly what is required in the example workbook

Sub Normalise()
Dim myRng As Range
Dim myArr()
Dim x as long
Dim y as long
Dim z as long

Set myRng = ThisWorkbook.Sheets("Current").Range("A2:CX108")
Z = 1
For x = 2 To 107
    For y = 1 To 100
        ReDim Preserve myArr(1 To 4, 1 To Z)
        myArr(1, Z) = myRng(x, 1)
        myArr(2, Z) = myRng(x, 2)
        myArr(3, Z) = myRng(1, y + 2)
        myArr(4, Z) = myRng(x, y + 2)
        Z = Z + 1
    Next y
Next x
ThisWorkbook.Sheets("desired").Range("A3:D" & Z + 1) = Application.Transpose(myArr)
End Sub

Open in new window


If the code needs to be more "flexible" can change the code if required.
pivotDesired.xlsm
0
 
LVL 50

Accepted Solution

by:
Ingeborg Hawighorst (Microsoft MVP / EE MVE) earned 1600 total points
ID: 38852633
Hello,

this can be done with a "reverse pivot", but first we need to change the source a bit:

Insert a column after column B, put a label in row 2 and in row 3 enter the formula

=A3&"-"&B3

Copy down. Now for the reverse Pivot.

1.  click a cell in the table and then use Alt - D - P to bring up the good, old Pivot Table wizard (yes, it's still there!)
2. in the first step, click "Multiple consolidation ranges" and Next
3. in Step 2a click "I will create the page fields" and Next
4. in Step 2b select the range, starting with the newly inserted column. Do not include columns A and B.  -- then click Next
5. in Step 3 select "new Worksheet" and click Finish

You will now see a pivot table. In the Pivot table field pane, drag all the fields from the Column Labels and the Row Labels areas back up into the field list. You will see the pivot table reduced to one cell with a number and a label above.

Double-click the number.

This will create a sheet with the raw data. Now you only need to split the previously concatenated columns A and B. Insert a new column between A and B and perform a Text to Columns on column A, using the "-" as the delimiter.

cheers, teylyn
0
 

Author Comment

by:Rayne
ID: 38852799
Thanks everyone for your help

Teylyn, Please check attached. This is what I got so far.
I don’t understand what to do here?-
"In the Pivot table field pane, drag all the fields from the Column Labels and the Row Labels areas back up into the field list"

Can you explain? I dragged all the three fields out of there, after which I didn’t see anything
pivotSoFar.png
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 50
ID: 38852860
See the four panels at the bottom of the field list in the pivot pane? The upper right has the "Column" field in it. The lower left has the "Row" field in it. Click and drag these two items up into the field list, so that the two panes are empty and the only thing left is "Sum of Value" in the lower right hand box.

That will transform the pivot table into a one cell affair with a label. Then double click the number in the one pivot cell.
0
 
LVL 24

Assisted Solution

by:Steve
Steve earned 400 total points
ID: 38852863
Cool method Teylyn:

Rayne, all you now do is drag the row and column off the column and row label areas..
So as to just leave the "Sum Of"

Then double click the large number that is left.
This will create the same data as the macro.
Cool.

I am sure that this would be a great topic for an article. ;)
0
 
LVL 50
ID: 38852894
>> I am sure that this would be a great topic for an article. ;)

John Walkenbach already wrote it up. http://spreadsheetpage.com/index.php/tip/creating_a_database_table_from_a_summary_table/
0
 
LVL 24

Expert Comment

by:Steve
ID: 38852912
Ahha... "good old" John,

His is are some of the few books I have in actual book form, and would heartily recommend.
(that and a dictionarry, as I am sure my spelling is getting worse as I get older)

But this is a great example of returning pivot data back to normal form.
Cheers,
Steve.
0
 

Author Comment

by:Rayne
ID: 38852952
Thanks Everyone for chipping in
Teylyn
All Hats off to you :)
Thanks a million
0
 

Author Comment

by:Rayne
ID: 38852973
Here's the follow up question...if anyone is interested :)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With its various features, Office 365 can not only help you with your day-to-day business tasks, it can also do wonders for your marketing campaign.
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question