Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Could someone help me in creating relationship between two tables(one table has compositekey)?

Here is my sample data table 1

 EventID   EffectiveDate   ExpirationDate    EventName

11/1/201012/30/2010Production
21/1/201112/30/2011Injection
11/1/201212/30/2012Downtime
31/1/201312/30/2013Deferement
11/1/201412/30/2014LossProduction
41/1/201512/30/2015Constraint
51/1/201612/30/2016Shut-In

 

Table 2 

EventID       ChildID     ChildDate          ChildName

1A5/5/2010OIL
1B4/4/2014GAS
2C3/2/2011WATER
3D2/2/2013CO2
4E3/3/2015O2
5F4/4/2016N2
    

 

Expected result in the  below format 

EventID       EffectiveDate    ChildDate         ChildID        ChildName

11/1/20105/5/2010AOIL
21/1/20113/2/2011CWATER
11/1/2012   
31/1/20132/2/2013DCO2
11/1/20144/4/2014BGAS
41/1/20153/3/2015EO2
51/1/20164/4/2016FN2

 

In SQL server i can create relationship like 

from Table 1 Join Table2

ON table1.EventID=table2.EventID AND table2.ChildDate BETWEEN table1.EffectiveDate AND Table1.ExpirationDate.

 

Could anyone help me to create the relationships between theese two tables in Power BI.

1 ACCEPTED SOLUTION
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous ,

 

You could create a calculated table.

Result table = 
SELECTCOLUMNS (
    GENERATEALL (
        table1,
        VAR Table1ID = table1[EventID]
        VAR Table1EffectiveDate = table1[EffectiveDate]
        VAR Table1ExpirationDate = table1[ExpriationDate]
        RETURN
            SELECTCOLUMNS (
                FILTER (
                    table2,
                    table2[EventID] = table1[EventID]
                        && table2[ChildDate] >= Table1EffectiveDate
                        && table2[ChildDate] <= Table1ExpirationDate
                ),
                "ChildID", table2[ChildID],
                "ChildName", table2[ChildName],
                "ChildDate", table2[ChildDate]
            )
    ),
    "EventID", [EventID],
    "EffectiveDate", [EffectiveDate],
    "ChildDate", [ChildDate],
    "ChildID", [ChildID],
    "ChildName", [ChildName]
)

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous ,

 

You could create a calculated table.

Result table = 
SELECTCOLUMNS (
    GENERATEALL (
        table1,
        VAR Table1ID = table1[EventID]
        VAR Table1EffectiveDate = table1[EffectiveDate]
        VAR Table1ExpirationDate = table1[ExpriationDate]
        RETURN
            SELECTCOLUMNS (
                FILTER (
                    table2,
                    table2[EventID] = table1[EventID]
                        && table2[ChildDate] >= Table1EffectiveDate
                        && table2[ChildDate] <= Table1ExpirationDate
                ),
                "ChildID", table2[ChildID],
                "ChildName", table2[ChildName],
                "ChildDate", table2[ChildDate]
            )
    ),
    "EventID", [EventID],
    "EffectiveDate", [EffectiveDate],
    "ChildDate", [ChildDate],
    "ChildID", [ChildID],
    "ChildName", [ChildName]
)

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

I appriciate your response Yuliana Gu @v-yulgu-msft,.

Thanks for your query!

I have 12 other tables with same criteria, do i have to join all of them? or can i use Filter in Relationships pane(when creating the relationships)? 

 

Appriociate your feedback

@Anonymous 

Hi @Anonymous ,

 

I have 12 other tables with same criteria, do i have to join all of them?

I'm afraid you may have to do that.

 

or can i use Filter in Relationships pane(when creating the relationships)? 

In such a scenario, it is not possible.

 

Regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors