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
spizzo
Regular Visitor

Join table with composed date and string keys

Hi Folks,

i'm a PowerBI's newbie , so i think you'll be able to help me in my first steps.

 

I have two tables, one for employees list of my company, the other for attendance events .

So, employees list has a specific PK but isn't a FK of attendance events.

THE TWO Tables are related by this join condition:

 

EVENTS.IDEMPLOY = EMPLOYEES.IDEMPLOY AND ( EVENTS.EVENT_DATE BETWEEN EMPLOYEES.INITIAL_DATE AND EMPLOYEES.FINAL_DATE )

 

I try to use Manage Relationships to make a similar join, but POWERBI dosn't like multiple records for join condition.

I try to make a merge table, but the result isn't i need.

 

There is anybody can help me?

 

Thank you all for your understanding and 

for all your assistance

 

Simone

 

example files HERE

2 ACCEPTED SOLUTIONS

Right, the column in your two tables will be calculated differently.

 

In your Employee table, you would do something like:

 

JoinColumn = [EmployeeID] & "1"

In your Events column, you would have something like:

 

JoinColumn = IF([Date]>RELATED(Employees[StartDate]),IF([Date]<RELATED(Employees[EndDate],[Employee] & "1",[Employee] & "0"),[Employee] & "0")


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

Eric_Zhang
Microsoft Employee
Microsoft Employee

@spizzo

 

I'd prefer a merge table.

 

Merge Table =
SELECTCOLUMNS (
    FILTER (
        CROSSJOIN ( EMPLOYEE, EVENTS ),
        EMPLOYEE[IDEMPLOY] = EVENTS[IDEMPLOY]
            && EMPLOYEE[INIT_DATE] <= EVENTS[DATE_EVENT]
            && EVENTS[DATE_EVENT] <= EMPLOYEE[FINAL_DATE]
    ),
    "IDEMPLOY", EMPLOYEE[IDEMPLOY],
    "CATEGORY", EMPLOYEE[CATEGORY],
    "FINAL_DATE", EMPLOYEE[FINAL_DATE],
    "FLNUMROW", EMPLOYEE[FLNUMROW],
    "IDCOMPANY", EMPLOYEE[IDCOMPANY],
    "IDEMPLOY_ALT_KEY", EMPLOYEE[IDEMPLOY_ALT_KEY],
    "INIT_DATE", EMPLOYEE[INIT_DATE],
    "DATE_EVENT", EVENTS[DATE_EVENT],
    "IDEVENT", EVENTS[IDEVENT],
    "QTA_EVENT", EVENTS[QTA_EVENT]
)

View solution in original post

6 REPLIES 6
Eric_Zhang
Microsoft Employee
Microsoft Employee

@spizzo

 

I'd prefer a merge table.

 

Merge Table =
SELECTCOLUMNS (
    FILTER (
        CROSSJOIN ( EMPLOYEE, EVENTS ),
        EMPLOYEE[IDEMPLOY] = EVENTS[IDEMPLOY]
            && EMPLOYEE[INIT_DATE] <= EVENTS[DATE_EVENT]
            && EVENTS[DATE_EVENT] <= EMPLOYEE[FINAL_DATE]
    ),
    "IDEMPLOY", EMPLOYEE[IDEMPLOY],
    "CATEGORY", EMPLOYEE[CATEGORY],
    "FINAL_DATE", EMPLOYEE[FINAL_DATE],
    "FLNUMROW", EMPLOYEE[FLNUMROW],
    "IDCOMPANY", EMPLOYEE[IDCOMPANY],
    "IDEMPLOY_ALT_KEY", EMPLOYEE[IDEMPLOY_ALT_KEY],
    "INIT_DATE", EMPLOYEE[INIT_DATE],
    "DATE_EVENT", EVENTS[DATE_EVENT],
    "IDEVENT", EVENTS[IDEVENT],
    "QTA_EVENT", EVENTS[QTA_EVENT]
)

@Eric_Zhang : thank you Eric, i used your solution and every thing works like i need...

Greg_Deckler
Community Champion
Community Champion

Create a column in each table that combines the fields. Then, use those columns to relate your tables.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler

Ok, i supposed to do it, but there are a variety of dates in event table and thera are only two dates in employees tables.

 

I which kind i can relate those new columns?

 

Thanks & Regards

 

 

Right, the column in your two tables will be calculated differently.

 

In your Employee table, you would do something like:

 

JoinColumn = [EmployeeID] & "1"

In your Events column, you would have something like:

 

JoinColumn = IF([Date]>RELATED(Employees[StartDate]),IF([Date]<RELATED(Employees[EndDate],[Employee] & "1",[Employee] & "0"),[Employee] & "0")


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler thank you Smiley Very Happy

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

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

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.