简体   繁体   中英

Excel/Google Sheets Transpose Column into Row Headers

I have a large amount of website page view data. The exported format is:

Page    | Date (mm/yy) | View Count
-----------------------------------                                                                
Page 1  | 01/18        | 150                                
Page 1  | 02/18        | 250                                
Page 1  | 03/18        | 350                                
Page 1  | 04/18        | 450
Page 2  | 01/18        | 150                                
Page 2  | 02/18        | 250                                
Page 2  | 03/18        | 350                                
Page 2  | 04/18        | 450

What I would like to do is format the data like this:

Page    | 01/18 | 02/18
-----------------------
Page 1  | 150   | 250                                
Page 2  | 150   | 250                                
Page 3  | 150   | 250                                
Page 4  | 150   | 250                                

What you're after can be done with a Pivot table with a few clicks.

在此处输入图片说明

Best practice in Excel:

  • turn your source data into an Excel Table object with Ctrl-T or Insert > Table
  • with a cell in the table selected, use Insert > Pivot Table
  • drag the page into the Rows area
  • drag the date into the Rolumns area
  • drag the View Count into the Values area

With an Excel Table as the source, when you add more data to your source, you can simply click a cell in the pivot table and use Data > Refresh All to, well, refresh the pivot table.

Just a few clicks, no formulas.

=query({A:C}, "select Col1, sum(Col3) where Col3 is not null group by Col1 pivot Col2")

  • pivot does what you wanted

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM