Power Query: Project Population – Part 2
26 April 2023
Welcome to our Power Query blog. This week, I continue to transform selected data from a public source.
I have found some information on population growth provided by The World Bank, which I am using as an example of how to transform real-life data.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image1-1682009243.png/3c4053e9960dbd351de0257421d5798e.jpg)
I have downloaded the Excel file, and last week I extracted the queries I needed to Power Query:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image2-1682009631.png/07ea67b885a3079df77535f3c65f77b0.jpg)
I reduced the data by selecting only the columns I wanted to keep:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image3-1682009653.png/1e69f4de327761c37500bee2e34e6db0.jpg)
This time, I will identify and remove any unnecessary rows and continue to transform the data. Looking at the country names, I can see that some are regions and not countries:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image4-1682009678.png/be8eb973a47051fa3819f47580ce6469.jpg)
For example, row 2 is ‘African Eastern and Southern’ and row 8 is ‘Arab World’. Since I only want the country data, I can remove these by filtering on Currency Unit, and choosing ‘Remove Empty’:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image5-1682009709.png/698eeadba944024ee44131d0c681d4a5.jpg)
This leaves me with a smaller dataset of 13 columns and 217 rows.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image6-1682009739.png/68f1b000925af5bf2764c43ebc181827.jpg)
Now I can turn my attention to transforming the remaining data. The System of National Accounts column has excess words:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image7-1682009783.png/b6226d08c5dc1a31d14a2a79a22b0315.jpg)
I could split the column into numerical and text data, using the ‘Split column’ feature on the Transform tab, but I only need the year, so the remaining column would just need to be deleted.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image8-1682009813.png/1bbd5a75535cced4a14d5abf96a0946d.jpg)
Instead, I can extract the year as a range, since it always appears in the same position:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image9-1682009835.png/69e87bffd1b9905fef767b0d8a5ea2ec.jpg)
I want to start at position 17 (remembering the first position is zero [0]) and extract four [4] characters:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image10-1682009867.png/04599ed57a7de3f882e0c9b080e92bf7.jpg)
This gives me the years where the data is available, and I can change the data type to ‘Whole number’:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image11-1682009889.png/4ce525f8c1156e0d36815e13cadf31cd.jpg)
This is a good point to look at the names of the steps that have been generated:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image12-1682009918.png/48a0cd3e7a0fd93bfb0b7a040a67a492.jpg)
The first six [6] steps are fine, as I am reducing the data. However, ‘Extracted Text Range’ and ‘Changed Type 1’ could be improved:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image13-1682009959.png/6a12629330a0151622f46069b5203adf.jpg)
Changing the names has been achieved simply by right-clicking on the step and clicking ‘Rename’. Note that I could have chosen to remove spaces from the step names, which would remove the leading hash (#) from the step names in the Advanced Editor:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image14-1682009983.png/4606e9b7f38455d175bf4473928ffae1.jpg)
This depends how familiar you (and anyone else that might need to understand the query) are with M code.
That’s it for this week, next time I’ll continue transforming the queries.
Come back next time for more ways to use Power Query!