Merging Queries

The Countries table has quite a few columns that we don’t need. Let’s remove them so it’s easier to see the data that we will work with.

  1. Select the Countries table.
    CountriesTable

  2. Hold down Ctrl + Select headings of columns:

    • LastEditedBy
    • ValidFrom
    • ValidTo
    • Application.People

    Right click + Choose Remove Columns.
    RemoveColumns

The database has defined relationships between tables (called foreign keys).

  1. Click on the Expand icon to expand column Application.StateProvinces.
  2. Unselect Use original column name as prefix.
  3. Select only StateProvinceName and StateProvinceID. ApplicationStateProvinces

Now we’re going to combine Cities and Countries into one table as it is good data modeling practice (we’ll discuss this next module)

  1. Under Queries, select the Cities table.
  2. Go to Home Tab > Select Merge Queries > Click on Merge Queries MergeQueries
  3. Verify that Cities is selected.
    Use the middle dropdown menu to select Countries. MergeWizard1

  4. Select StateProvinceID in both tables (You need to have a matching key in order to merge between two tables) MergeWizard2

  5. Expand the new Countries column in the newly merged Cities table. Choose CountryName, Region and Subregion only. MergeColumns

  6. Right click Countries query and unselect Enable load. We don’t need the data from this table loaded into the model because we have already merged in the columns that we want. EnableLoad

  7. Power Query will warn you that any visuals you have attached to the Countries query will break. That’s fine.
    PossibleDataLoss

The Countries table will not show up in Data model View because we have disabled the load in the steps above.