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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
markgsmith01
Frequent Visitor

Returning values from a many to many relationship

I have an event table and an employee table that share a many to many relationship. I want to to polulate the role that an employee had at the time of the event. For example, the first event occurred to "Bob" on 1/4/2020, and I can see in the Employee table that  he was an Analyst at that date. But he was a consultant when the second event that involved "Bob" occurred.

 

Event Table

DateName
1/04/2020Bob
1/07/2020Bob
3/05/2021Jill
13/02/2022Fred


Employee Table

NameRoleStart DateEnd Date
BobAnalyst1/01/20201/06/2020
BobConsultant2/06/20201/01/2023
JillConsultant15/07/20183/12/2020
JillTrainer4/12/20201/01/2023
FredAnalyst1/05/2021

1/01/2023

 

Desired Result Event Table

DateNameRole
1/04/2020BobAnalyst
1/07/2020BobConsultant
3/05/2021JillTrainer
13/02/2022FredAnalyst

 

I've been banging my head against the wall for a while on this but I figure it shouldn't be that hard!?! Any help would be appreciated.

1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @markgsmith01 ,

 

try to add a calculated column in event table like:

column = 
VAR _name =[name]
VAR _date = [date]
VAR _result =
MAXX(
    FILTER(
        employee,
        employee[Name]=_name
            &&employee[Start Date]<=_date
            &&employee[End Date]>=_date
    ),
    employee[role]
)
RETURN _result

 

it worked like:

FreemanZ_0-1700212311750.png

 

View solution in original post

2 REPLIES 2
FreemanZ
Super User
Super User

hi @markgsmith01 ,

 

try to add a calculated column in event table like:

column = 
VAR _name =[name]
VAR _date = [date]
VAR _result =
MAXX(
    FILTER(
        employee,
        employee[Name]=_name
            &&employee[Start Date]<=_date
            &&employee[End Date]>=_date
    ),
    employee[role]
)
RETURN _result

 

it worked like:

FreemanZ_0-1700212311750.png

 

Thanks @FreemanZ . That's exactly what I want. This sort of scenario keeps coming up for me. The formula seems simple but my brain seems to take a bit to absorb it!

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.