Forum Discussion

sboobar's avatar
sboobar
Frequent Visitor
3 years ago
Solved

Merge 2 Tables matching date column and Index column

I have two tables/queries in Power BI that are already matched by an similar index column, however, both tables show daily data with different columns. I'm trying to figure out how to combined these two tables so that I have daily data for each index/item and all columns. Whenever I match on index ignoring date I'm not getting the results I want. Below is an example of what I am trying to achieve.

 

TABLE 1   
DateIndexGreen 
1/1/202317 
1/2/20231545 
1/3/2023168 
1/1/2023221 
1/2/20232547 
1/3/2023285 
1/1/20233312 
1/2/202330 
1/3/202334 
    
    
TABLE 2   
DateIndexRed 
1/1/202315 
1/2/2023164 
1/3/2023112 
1/1/2023278 
1/2/2023292 
1/3/2023241 
1/1/202332 
1/2/202337 
1/3/202337 
    
GOAL:   
DateIndexGreenRed
1/1/2023175
1/2/2023154564
1/3/202316812
1/1/202322178
1/2/2023254792
1/3/202328541
1/1/202333122
1/2/2023307
1/3/2023347
  • Hi sboobar 

     

    This is easy with the Merge Queries feature in Power Query. Merge queries overview - Power Query | Microsoft Learn

    Click on "Merge Queries" to open the Merge window, hold on "Ctrl" key on keyboard and select both Date and Index columns as the matching columns in two tables. Select "Full Outer" join kind in case that some row is missing in one table. Click "OK". 

    You will have a result similar to below. A new "Table 2" column appears. 

    Click the expand icon on "Table 2" column header and select only "Red" column to expand to the table. You will have the expected result then. 

     

    Best Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as Solution to help other members find it.

     

5 Replies

  • Hello sboobar,

     

    To achieve the goal, you need to perform a join operation between the two tables based on the "Date" and "Index" columns.

    • sboobar's avatar
      sboobar
      Frequent Visitor

      Thank you. I tried your formula below and unfortunately couldn't get it to work. JOIN did not appear when I was typing the formula.

       

      Combined = SUMX(JOIN('TABLE 1', 'TABLE 2', "Date", "Date", "Index", "Index"), [Green] + [Red])
    • Sahir_Maharaj's avatar
      Sahir_Maharaj
      Super User

      1. Load both tables into the data model.
      2. Right-click on one of the tables and select "New Measure".
      3. Write a DAX formula to combine the data from both tables, for example:

       

      Combined = SUMX(JOIN('TABLE 1', 'TABLE 2', "Date", "Date", "Index", "Index"), [Green] + [Red])
    • Sahir_Maharaj's avatar
      Sahir_Maharaj
      Super User

      3. Save the measure and close the formula bar.
      4. Go to the report view and create a pivot table using the "Date" and "Index" columns for Rows and the "Combined" measure for Values.


      This should give you the combined data you are looking for.

       

      Let me know if you require further assistance.

  • v-jingzhang's avatar
    v-jingzhang
    Community Support

    Hi sboobar 

     

    This is easy with the Merge Queries feature in Power Query. Merge queries overview - Power Query | Microsoft Learn

    Click on "Merge Queries" to open the Merge window, hold on "Ctrl" key on keyboard and select both Date and Index columns as the matching columns in two tables. Select "Full Outer" join kind in case that some row is missing in one table. Click "OK". 

    You will have a result similar to below. A new "Table 2" column appears. 

    Click the expand icon on "Table 2" column header and select only "Red" column to expand to the table. You will have the expected result then. 

     

    Best Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as Solution to help other members find it.