Pivot and Unpivot Data with Excel Power Query

Wide data and Tall data, also referred to as Pivoted and Unpivoted data, are common types of data layout. Yet, each has its own use. Wide data does not follow Tidy data rules that each variable should be represented in one column (field). An example of that is a dataset of CO2 emissions per country over 10 years where countries are listed in one column (as one variable) with their CO2 emissions listed row-wise across different years. In this scenario, each Year value is listed in a single column. Wide data is not suitable for data analysis, but it could be a desirable choice for data visualization.

In contrast to Wide data, Tall data (unpivoted) is structured, tidy data with each column (field) represents a single variable. Years, in the CO2 Emissions example, is a single column that lists all values of years, one per observation (row). This type of data is more efficient in data analysis. Hence, it is a common task to convert Wide data into Tall during the data cleaning and wrangling process.

That said, it is inevitable to encounter a situation in which you need to convert one type into another. While I’ve been using the spread() and gather() functions from the tidyverse library in R to do a quick conversion, Excel Power Query has emerged as rival to perform some data wrangling tasks in a slick and user-friendly manner. Watch this video to see how easy it is to convert data layout easily with Power Query.

NB: Data used in the movie is the annual production-based emissions of carbon dioxide (CO2), measured in million tons. Source: CO₂ and Greenhouse Gas Emissions – Our World in Data

Pivot and Unpivot Data with Power Query

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply