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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.