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

First Post: If Exam is within Assignment Start Time and End Time - return Assignment Name?

My first post here.  Sorry if this has been answered already, but I can't seem to find it.  Thank you!

 

I am trying to find a way to link between two Power BI tables:

Table 1:  Exam Table (fact table) than includes Dates and Times of exams and the Physician who completed the Exam

Table 2: Schedule Assignment Table with the Schedule Assignments of about 100 assigned Physicians who complete Exams. Each Schedule Shift Assignment for each Physician has a Start Date and Time and End Date and Time and a unique identifier (ScheduleEntryID)


I want to write a formula (DAX?) that looks at each Exam in the Exam Table to see if the performed ExamDateTime and Physician is on or between a Physician Schedule Shift Start Datetime and the Schedule Shift End Datetime.  If the exam is within an Assignment, return a calculated column in the Exam table that contains the ScheduleEntryID, otherwise return "NoMatch"

 

This will help me analyze the productivity of each Shift and Physician.

Example File 

EXAM TABLE:

Physician NameExam Final Date & TimePatient
Anderson, Alan4/15/2022 23:10Patient A
Brown, Bob4/15/2022 12:06Patient B
Brown, Bob4/16/2022 0:06Patient D
Brown, Bob4/15/2022 11:06Patient C

 

SCHEDULE TABLE:

Schedule Entry IDStart DateStart TimeEnd DateEnd TimeAssignment KeyAssignment NameLast NameFirst Name
10004/15/20224:00:00 PM4/16/20222:00:00 AMa123Assignment AAndersonAlan
10224/15/20228:00:00 AM4/15/20225:00:00 PMb234Assignment BBrownBob

 

IDEAL OUTPUT:

Physician NameExam Final Date & TimePatientSchedule Entry IDStart DateStart TimeEnd DateEnd TimeAssignment KeyAssignment Name
Anderson, Alan4/15/2022 23:10Patient A10003/31/20224:00:00 PM4/1/20222:00:00 AMa123Assignment A
Brown, Bob4/15/2022 12:06Patient B10223/31/20228:00:00 AM3/31/20225:00:00 PMb234Assignment B
Brown, Bob4/16/2022 0:06Patient DNo Match      
Brown, Bob4/15/2022 11:06Patient C10223/31/20228:00:00 AM3/31/20225:00:00 PMb234Assignment B

 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @bdunford 
Here is a sample file with the solution https://we.tl/t-UWUhGE0RKI

First you need to create a full name calculated column in the schedule table. this will simplify the calculation by relying on a relationship based on Physician Name.

1.png2.png

Then you can use the Exam table as a base table in the visual then grapping the columns from the schedule table using mesures

Schedule Entry ID = 
VAR ExanmDateTime = SELECTEDVALUE ( Exam[Exam Final Date & Time] )
VAR MatchingRow = 
    FILTER ( 
        Schedule, 
        VAR CurrentStart = Schedule[Start Date] + Schedule[Start Time] - 1
        VAR CurrentEnd = Schedule[End Date] + Schedule[End Time] - 1
        RETURN
            ExanmDateTime >= CurrentStart && ExanmDateTime <= CurrentEnd
    )
VAR EntryID = MAXX ( MatchingRow, Schedule[Schedule Entry ID] )
VAR Result = COALESCE ( EntryID, "No Match" )
RETURN
    Result
Start Date/Time = 
VAR ExanmDateTime = SELECTEDVALUE ( Exam[Exam Final Date & Time] )
VAR MatchingRow = 
    FILTER ( 
        Schedule, 
        VAR CurrentStart = Schedule[Start Date] + Schedule[Start Time] - 1
        VAR CurrentEnd = Schedule[End Date] + Schedule[End Time] - 1
        RETURN
            ExanmDateTime >= CurrentStart && ExanmDateTime <= CurrentEnd
    )
VAR Result = SUMX ( MatchingRow, Schedule[Start Date] + Schedule[Start Time] - 1 )
RETURN
    Result
End Date/Time = 
VAR ExanmDateTime = SELECTEDVALUE ( Exam[Exam Final Date & Time] )
VAR MatchingRow = 
    FILTER ( 
        Schedule, 
        VAR CurrentStart = Schedule[Start Date] + Schedule[Start Time] - 1
        VAR CurrentEnd = Schedule[End Date] + Schedule[End Time] - 1
        RETURN
            ExanmDateTime >= CurrentStart && ExanmDateTime <= CurrentEnd
    )
VAR Result = SUMX ( MatchingRow, Schedule[End Date] + Schedule[End Time] - 1 )
RETURN
    Result
Assignment Key = 
VAR ExanmDateTime = SELECTEDVALUE ( Exam[Exam Final Date & Time] )
VAR MatchingRow = 
    FILTER ( 
        Schedule, 
        VAR CurrentStart = Schedule[Start Date] + Schedule[Start Time] - 1
        VAR CurrentEnd = Schedule[End Date] + Schedule[End Time] - 1
        RETURN
            ExanmDateTime >= CurrentStart && ExanmDateTime <= CurrentEnd
    )
VAR Result = MAXX ( MatchingRow, Schedule[Assignment Key] )
RETURN
    Result
Assignment Name = 
VAR ExanmDateTime = SELECTEDVALUE ( Exam[Exam Final Date & Time] )
VAR MatchingRow = 
    FILTER ( 
        Schedule, 
        VAR CurrentStart = Schedule[Start Date] + Schedule[Start Time] - 1
        VAR CurrentEnd = Schedule[End Date] + Schedule[End Time] - 1
        RETURN
            ExanmDateTime >= CurrentStart && ExanmDateTime <= CurrentEnd
    )
VAR Result = MAXX ( MatchingRow, Schedule[Assignment Name] )
RETURN
    Result

3.png

View solution in original post

1 REPLY 1
tamerj1
Super User
Super User

Hi @bdunford 
Here is a sample file with the solution https://we.tl/t-UWUhGE0RKI

First you need to create a full name calculated column in the schedule table. this will simplify the calculation by relying on a relationship based on Physician Name.

1.png2.png

Then you can use the Exam table as a base table in the visual then grapping the columns from the schedule table using mesures

Schedule Entry ID = 
VAR ExanmDateTime = SELECTEDVALUE ( Exam[Exam Final Date & Time] )
VAR MatchingRow = 
    FILTER ( 
        Schedule, 
        VAR CurrentStart = Schedule[Start Date] + Schedule[Start Time] - 1
        VAR CurrentEnd = Schedule[End Date] + Schedule[End Time] - 1
        RETURN
            ExanmDateTime >= CurrentStart && ExanmDateTime <= CurrentEnd
    )
VAR EntryID = MAXX ( MatchingRow, Schedule[Schedule Entry ID] )
VAR Result = COALESCE ( EntryID, "No Match" )
RETURN
    Result
Start Date/Time = 
VAR ExanmDateTime = SELECTEDVALUE ( Exam[Exam Final Date & Time] )
VAR MatchingRow = 
    FILTER ( 
        Schedule, 
        VAR CurrentStart = Schedule[Start Date] + Schedule[Start Time] - 1
        VAR CurrentEnd = Schedule[End Date] + Schedule[End Time] - 1
        RETURN
            ExanmDateTime >= CurrentStart && ExanmDateTime <= CurrentEnd
    )
VAR Result = SUMX ( MatchingRow, Schedule[Start Date] + Schedule[Start Time] - 1 )
RETURN
    Result
End Date/Time = 
VAR ExanmDateTime = SELECTEDVALUE ( Exam[Exam Final Date & Time] )
VAR MatchingRow = 
    FILTER ( 
        Schedule, 
        VAR CurrentStart = Schedule[Start Date] + Schedule[Start Time] - 1
        VAR CurrentEnd = Schedule[End Date] + Schedule[End Time] - 1
        RETURN
            ExanmDateTime >= CurrentStart && ExanmDateTime <= CurrentEnd
    )
VAR Result = SUMX ( MatchingRow, Schedule[End Date] + Schedule[End Time] - 1 )
RETURN
    Result
Assignment Key = 
VAR ExanmDateTime = SELECTEDVALUE ( Exam[Exam Final Date & Time] )
VAR MatchingRow = 
    FILTER ( 
        Schedule, 
        VAR CurrentStart = Schedule[Start Date] + Schedule[Start Time] - 1
        VAR CurrentEnd = Schedule[End Date] + Schedule[End Time] - 1
        RETURN
            ExanmDateTime >= CurrentStart && ExanmDateTime <= CurrentEnd
    )
VAR Result = MAXX ( MatchingRow, Schedule[Assignment Key] )
RETURN
    Result
Assignment Name = 
VAR ExanmDateTime = SELECTEDVALUE ( Exam[Exam Final Date & Time] )
VAR MatchingRow = 
    FILTER ( 
        Schedule, 
        VAR CurrentStart = Schedule[Start Date] + Schedule[Start Time] - 1
        VAR CurrentEnd = Schedule[End Date] + Schedule[End Time] - 1
        RETURN
            ExanmDateTime >= CurrentStart && ExanmDateTime <= CurrentEnd
    )
VAR Result = MAXX ( MatchingRow, Schedule[Assignment Name] )
RETURN
    Result

3.png

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!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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.