Forum Discussion

jalaomar's avatar
jalaomar
Helper IV
4 years ago
Solved

Combine datasources

Hi all,

 

Is it possible to combine different datasources that have information sitting in different datasources for the same project.

please see attached screenshot of the outcome I am looking for.

 

Project A has Date1 in Table1

Project A has Date2 in Table2

 

How can combine these information in one single table?

 

BR

J

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi jalaomar ,

    You can create a calculated column as below to get the Date2 and check whether that is what you want...

    NDate2 = 
    VAR _date2 =
        CALCULATE (
            MAX ( 'Table2'[Date2] ),
            FILTER (
                'Table2',
                'Table2'[Project] = 'Table1'[Project]
                    && 'Table2'[Date2] >= 'Table1'[Date1]
            )
        )
    RETURN
        IF ( ISBLANK ( 'Table1'[Date2] ), _date2, 'Table1'[Date2] )

    If the above one is not working for your scenario, please provide more sample data with Text format and your expected result included with backend logic and special examples. Thank you.

    Best Regards

8 Replies

  • In Power Query append the tables.
    Then in Power Query group the new table by project and Date1 with max Date2.

    • jalaomar's avatar
      jalaomar
      Helper IV

      Hi speedramps , Thanks! I know Append query but never done this grouping. would you like to show from a screenshot how that is done?

       

      BR

      J

  • How do you know that the green date belongs in that row?

     

    If you had another row in the blue table,

    A  2021-05-31 (blank)

    would the green date pair with this row, the top row, or both?

    • jalaomar's avatar
      jalaomar
      Helper IV

      Hi, I tried to do the steps but it's not working. What am I doing wrong?

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi jalaomar ,

    You can create a calculated column as below to get the Date2 and check whether that is what you want...

    NDate2 = 
    VAR _date2 =
        CALCULATE (
            MAX ( 'Table2'[Date2] ),
            FILTER (
                'Table2',
                'Table2'[Project] = 'Table1'[Project]
                    && 'Table2'[Date2] >= 'Table1'[Date1]
            )
        )
    RETURN
        IF ( ISBLANK ( 'Table1'[Date2] ), _date2, 'Table1'[Date2] )

    If the above one is not working for your scenario, please provide more sample data with Text format and your expected result included with backend logic and special examples. Thank you.

    Best Regards

    • jalaomar's avatar
      jalaomar
      Helper IV

      Hi Anonymous , Thank you! Will try it out today. Just a question, will this calculated column work if I append the two tables?

      because i need to append to be able to have all the ID's in one table. 

       

      BR

      J

    • jalaomar's avatar
      jalaomar
      Helper IV

      Hi Anonymous, I could not make it work with my appended query.

      Below you can see that I have 3 tabels with source data and i want all information for all projects to be in the same table, hence I need to append them (due to KPI calculation)

      Could you maybe support?

       

      GPR Data

      Project IDBaselineActual
      A2021-12-23 
      B2021-11-02 
      C2021-10-142021-10-14
      D2021-04-232021-04-20

       

      Project File Data

      Project IDBaselineActual
      E2021-11-122021-11-13
      F2021-12-23 

       

      PV Data

      Project IDBaselineActual
      A 2021-12-25
      B 2021-12-27
      F 2021-12-30

       

      Expected Outcome (Append the 3 above tavles as new query in Power BI)

       

      Project Performance 

      Project IDBaselineActual
      A2021-12-232021-12-25
      B2021-11-022021-12-27
      C2021-10-142021-10-14
      D2021-04-232021-04-20
      E2021-11-122021-11-13
      F2021-12-232021-12-30