4. Join Data from Different Tables (one to one)

In order to calculate the percentage of people without access to improved water sources we need to join the two tables that we have imported in our GeoPackage in the previous steps.

Because we need to join features based on country code and year we need to create a new field that combines both.

1. Open the attribute table of the population layer.

2. Click  to open the Field Calculator dialog.

3. Create a new field with the name CODE_YEAR and Output field type Text (string). Under Expression create the following expression:

 "Code"  ||  "Year" 


This will concatenate the text in the "Code" field with the text in the "Year" field.

4. Click OK to calculate the result.

5. Click  to toggle off editing mode and click Save to store the results. Close the attribute table.

6. Repeat this for the number-without-improved-water table so it also has a new field with the Code and the Year called CODE_YEAR.


Now we can join both tables.

7. Right-click on the number-without-improved-water layer and choose Properties... from the context menu.

8. Go to the Joins tab.


9. Click the  button to add a join.

10. Choose population as Join layer and choose CODE_YEAR for both Join field and Target field.

11. Expand Joined fields and check the box. Check the box for Population so it will only join this field.

12. Expand and check the box for Custom field name prefix and delete the text there.


13. Click OK to continue.

14. Expand Join layer and check if the settings are okay. Then click OK to apply and close the dialog.


15. Check the result in the attribute table of number-without-improved-water. Note that the years that did not match were not added to the table.

In the next section we'll calculate the percentage of population without access to improved water sources.