Forum Discussion

lukaspowerbi's avatar
lukaspowerbi
Helper II
8 years ago
Solved

Joining multiple tables/queries

I am trying to build a summary table displaying countries in one column and some numbers (Members,Joins,Expires) for those countries in other columns.

 

That is my desired (simplified) result:

Country      Members       Joins    Expires

Canada       50                  20        15

USA            80                  30         25

UK              40                  25        10

 

The way I have it set up now is having 3 seperate queries/tables (Members,Joins,Expires) each query feeds one report.

In other words, my members report has a table displaying Country and Members columns,

                         my Joins report has a table displaying Country and Joins columns,

                         and same for Expires, a table displaying Country and Expires columns.

Current State:

Country      Members      

Canada       50                  

USA            80                  

UK              40             

 

Country         Joins   

Canada          20       

USA               30       

UK                 25   

 

Country      Expires

Canada       15

USA            25

UK              10

    

The way these three tables are created is using a distinct member ID per country.

Any thoughts?

 

 

 

 

  • Phil_Seamark's avatar
    Phil_Seamark
    8 years ago

    Hi lukaspowerbi

     

    Sorry for the late reply.  Did you get this one sorted?

     

    I'm guessing there is a subtle difference in the spelling, or even a rogue space that needs to be cleaned for an exact match

6 Replies

  • Phil_Seamark's avatar
    Phil_Seamark
    Microsoft Employee

    Hi lukaspowerbi

     

    Have you considered merging the tables using then Query Editor?  

     

     

    This will allow you to create a new table that looks like your desired output.

     

    Otherwise we can do this in DAX if you prefer

    • lukaspowerbi's avatar
      lukaspowerbi
      Helper II

      Thank you.

      I think I'll ttry to use the merge queries function and see how it goes. 

  • Hi Phil_Seamark

    I am not sure what's easier to explain so that I can accomplish this whether dax or merging queries.....

     

    I am not sure if merging queries solves the problem. Can you give me an example of how to merge let's say two tables/queries?

    In both tables there are countries that may not be in another table. 

     

    Country      Members      

    Canada       50                  

    USA            80                  

    UK              40   

    Brazil          20         

     

    Country         Joins   

    Canada          20       

    USA               30   

    UK                 25

    Australia        10 

     

    My desired output is to combine all countries in both columns:

    Country      Members     Joins 

    Canada       50                  20

    USA            80                  30

    UK              40                  25

    Brazil          20                  0

    Australia     0                    10

     

    Member IDs per country is the formula (2 columns)

    Hope it makes sense.

     

    • Phil_Seamark's avatar
      Phil_Seamark
      Microsoft Employee

      HI lukaspowerbi,

       

      In the Query Editor, I created the following two tables.

       

      Table1

      and Table2

       

      I then chose the Merge Queries as New option

       

      I then configure the Merge dialog as follows.  Be sure to click the Country column in bot tables. 

       

      In the newly created table, click the "expand columns" button in the top right hand corner

       

      Configure the dialog as follows and click ok

       

      Now add a new column to combine the two contry fields as follows

       

       

      Delete the 1st and 3rd columns ("Country" and "Table2.Country"), and rename the 5th column from "Custom" to "Country".

       

      Highlight the 1st and 2nd columns and use the Replace Values function on the Home table to convert nulls to zeros.

       

       

      Then rename, and reorder your columns and you are good to go.

       

       

      • lukaspowerbi's avatar
        lukaspowerbi
        Helper II

        Hi Phil_Seamark.
        You have been a great help. Thank you!!!

         

        I have one more thing that I would like to ask you about if there is a way to do some work around.

        I added a custom column and replaced null values from the first Country column by values in the 5th column.
        However, there is Papua New Guinea that causes a bit issue. I attached a screenshot where I highlighted the issue in the pic below.