Monday, February 4, 2019

How to Quickly Transpose Data in Excel

If you have a dataset and you want to transpose it in Excel (which means converting rows into columns and columns into rows), doing it manually is a complete NO NO!

Transpose Data in Excel

In this tutorial, you’ll learn the techniques to transpose data in Excel:
  • Transpose Data using Paste Special.
  • Transpose Data using Paste Special and Find and Replace.
  • Transpose Data using Formulas.
  • Transpose Data using Power Query.

Transpose Data using Paste Special

Paste Special can do a lot of amazing things, and one such thing is to transpose data in Excel.
Suppose you have a dataset as shown below:
Transpose Data in Excel - Dataset
This data has the regions in a column and quarters in a row.
Now for some reason, if you need to transpose this data, here is how you can do this using paste special:
  • Select the data set (in this case A1:E5).
  • Copy the dataset (Control + C) or right-click and select copy.Transpose Data in Excel - Copy
  • Now you can paste the transposed data in a new location. In this example, I want to copy in G1:K5, so right-click on cell G1 and select paste special.Transpose Data in Excel - Paste Special G1
  • In the paste special dialogue box, check the transpose option in the bottom right.
  • Click OK.
This would instantly copy and paste the data but in such a way that it has been transposed. Below is a demo showing the entire process.
The steps shown above copies the value, the formula (if any), as well as the format. If you only want to copy the value, select ‘value’ in the paste special dialog box.
Note that the copied data is static, and if you make any changes in the original data set, those changes would not be reflected in the transposed data.
If you want these transposed cells to be linked to the original cells, you can combine the power ofFind & Replace with Paste Special.

Transpose Data using Paste Special and Find and Replace

Using Paste Special alone gives you static data. This means that if your original data changes and you want the transposed data to be updated as well, then you need to use Paste Special again to transpose it.
Here is a cool trick you can use to transpose the data and still have it linked with the original cells.
Suppose you have a dataset as shown below:
Transpose Data in Excel - Dataset
Here are the steps to transpose the data but keep the links intact:
  • Select the data set (A1:E5).
  • Copy it (Control + C, or right-click and select copy).Transpose Data in Excel - copy data
  • Now you can paste the transposed data in a new location. In this example, I want to copy in G1:K5, so right-click on cell G1 and select paste special.Transpose Data in Excel - Paste Special G1
  • In the Paste Special dialog box, click on the Paste Link button. This will give you the same data set, but here the cells are linked to the original data set (for example G1 is linked to A1, and G2 is linked to A2, and so on).Transpose Data in Excel - paste link
  • With this new copied data selected, Press Control + H (or go to Home –> Editing –> Find & Select –> Replace). This will open the Find & Replace dialog box.Transpose Data in Excel - Find & Replace
  • In the Find & Replace dialog box, use the following:
    • In Find what: =
    • In Replace with: !@# (note that I am using !@# as it’s a unique combination of characters that is unlikely to be a part of your data. You can use any such unique set of characters).Transpose Data in Excel - replace dialog box
  • Click on Replace All. This will replace the equal to from the formula and you will have !@# followed by the cell reference in each cell.Transpose Data in Excel - replaced data
  • Right-click and copy the data set (or use Control + C).Transpose Data in Excel - copy replaced data
  • Select a new location, right-click and select paste special. In this example, I am pasting it in cell G7. You can paste it anywhere you want.Transpose Data in Excel - paste special replaced data
  • In the Paste Special dialog box, select Transpose and click OK.Transpose Data in Excel - transpose replaced data
  • Copy paste this newly created transposed data to the one from which it is created.Transpose Data in Excel - copying transposed data
  • Now open the Find and Replace dialog box again and replace !@# with =.Transpose Data in Excel - find replace again
This will give you a linked data that has been transposed. If you make any changes in the original data set, the transposed data would automatically update.
Transpose Data in Excel - Linked
Note: Since our original data has A1 as empty, you would need to manually delete the 0 in G1. The 0 appears when we paste links, as a link to an empty cell would still return a 0. Also, you’d need to format the new dataset (you can simply copy paste the format only from the original dataset).

Transpose Data using Excel TRANSPOSE Function

Excel TRANSPOSE function – as the name suggests – can be used to transpose data in Excel.
Suppose you have a dataset as shown below:
Transpose Data in Excel - Dataset
Here are the steps to transpose it:
  • Select the cells where you want to transpose the dataset. Note that you need to select the exact number of cells as the original data. So for example, if you have 2 rows and 3 columns, you need to select 3 rows and 2 columns of cells where you want the transposed data. In this case, since there are 5 rows and 5 columns, you need to select 5 rows and 5 columns.Transpose Data in Excel - select cells transpose function
  • Enter =TRANSPOSE(A1:E5) in the active cell (which should be the top left cell of the selection and press Control Shift Enter.
This would transpose the dataset.
Transpose Data in Excel - transpose function
Here are a few things you need to know about TRANSPOSE function:
  • It is an array function, so you need to use Control Shift Enter and not just Enter.
  • You can not delete a part of the result. You need to delete the entire array of values that the TRANSPOSE function returns.
  • Transpose function only copies the values, not the formatting.

Transpose Data Using Power Query

Power Query is a powerful tool that enables you to quickly transpose data in Excel.
Power Query is a part of Excel 2016 (Get & Transform in the Data tab) but if you’re using Excel 2013 or 2010, then you need to install it as an add-in.
Suppose you have the data set as shown below:
Transpose Data in Excel - Dataset
Here are the steps to transpose this data using Power Query:

In Excel 2016

  • Select the data and go to Data –> Get & Transform –> From Table.Transpose Data in Excel - from table
  • In the Create Table dialogue box, make sure the range is correct and click OK. This will open the Query Editor dialog box.Transpose Data in Excel - power query ok
  • In the Query editor dialog box, select Transform tab.Transpose Data in Excel - transform
  • In the Transform tab, go to Table –> Use First Row as Headers –> Use Headers as First Row. This ensures that the first row (that contains headers: Q1, Q2, Q3, and Q4) are also treated as data and transposed.Transpose Data in Excel - power query header1
  • Click on Transpose. This would instantly transpose the data.Transpose Data in Excel - power query transpose
  • Click on Use First Row as Headers. This would now make the first row of the transposed data as headers.Transpose Data in Excel - power query header2
  • Go to File –> Close and Load. This will close the Power Editor window and create a new sheet that contains the transposed data.Transpose Data in Excel - power query close and load
Note that since the top left cell of our data set was empty, it gets a generic name Column1 (as shown below). You can delete this cell from the transposed data.
Transpose Data in Excel - power query result

In Excel 2013/2010

In Excel 2013/10, you need to install Power Query as an add-in.
Click here to download the plugin and get installation instructions.
Once you have installed Power Query, go to Power Query –> Excel Data –> From Table.
Transpose Data in Excel - 2010-13 Power Query
This will open the create table dialog box. Now follow the same steps as shown for Excel 2016.

No comments:

Post a Comment