Forum Discussion

Marcottech's avatar
Marcottech
Regular Visitor
10 months ago
Solved

Add a column from a different query for which the value is determined by both a match and a date

Hi,

I have 2 different tables, each in a different query.

1. A table that defines the date a time for which some events (Adverse Events) occured to some people (Subject) from different group populations (Study).

2. A table that defines the date and time for which a important procedure (Dosing) was collected on each "Subject". The "Dosing" can be performed multiple time for a given "Subject"

 

I want to add 2 columns to the first table. The column should look for the "No" in the column "Is this a Pre-dose AE?", then look for a match with columns "Study" and "Subject", and finally select the data from the appropriate row from the "Dosing" table according to the date and time of the "Adverse Events"

1. A column that wil indicate the date and time of the first "Dosing" for that subject.

2. A column that wil indicate the date and time of the latest "Dosing" for that subject. So if an "Adverse Event" started between the 2nd and 3rd "Dosing" for that subject, the data should reflect the date and time of the 2nd "Dosing" for this subject.

 

Here's a sample of the tables I have, with the added "Expected results" table:

 

Table 1: Adverse Event

StudySubjectAdverse Event TitleStart TimeIs this a Pre-dose AE? 
A1AE 0110/19/2025 19:00Yes
A1AE 0210/21/2025 8:30No
A1AE 0310/22/2025 9:15No
A2AE 0110/22/2025 13:00No
B1AE 0110/10/2025 8:00No
B2AE 0210/17/2025 8:00No
C1AE 0110/23/2025 8:00No

 

Table 2: Dosing

StudySubjectPeriodDose NumberScheduled TimepointCollection Time
A111Day 110/20/2025 8:00
A112Day 210/21/2025 8:00
A113Day 310/22/2025 8:00
A211Day 110/20/2025 8:10
A212Day 210/21/2025 8:10
A213Day 310/22/2025 8:10
B111Day 110/10/2025 8:00
B122Day 110/17/2025 8:00
C111Day 110/20/2025 8:00

 

Expected Result:

StudySubjectAdverse Event TitleStart TimeIs this a Pre-dose AE? First Dosing Date/TimeLatest dosing Date/Time
A1AE 0110/19/2025 19:00Yesnullnull
A1AE 0210/21/2025 8:30No10/20/2025 8:0010/21/2025 8:00
A1AE 0310/22/2025 9:15No10/20/2025 8:0010/22/2025 8:00
A2AE 0110/22/2025 13:00No10/20/2025 8:1010/22/2025 8:10
B1AE 0110/10/2025 8:00No10/10/2025 8:0010/10/2025 8:00
B1AE 0210/17/2025 8:00No10/10/2025 8:0010/17/2025 8:00
C1AE 0110/23/2025 8:00No10/20/2025 8:0010/20/2025 8:00

 

My goal is ultimately to be able to determine if there is a recurence in events and to determine of the events all occur approximately around the same time. Once these columns are created I'll be able to calculate the duration I need to include in my visuals.

 

The tables will grow with time, so I need a formula that will take into account the new entries that will be entered (additional studies and subjects).

 

Thank you all for your support!

Christian

  • Hi Christian,

     

    Not sure if you want Power Query or DAX or what the relationships in your model look like, but as a first draft, DAX, try this...

     

     

    First Dosing for Subject = 
    CALCULATE(
        MIN(Dosing[Collection Time]), 
        FILTER(
            Dosing, 
            Dosing[Study] = 'Adverse Event'[Study] &&
            Dosing[Subject] = 'Adverse Event'[Subject] &&
            'Adverse Event'[Is this a Pre-dose AE?] = "No"
        )
    )

     

    Last Dosing Before AE = 
    CALCULATE(
        MAX(Dosing[Collection Time]), 
        FILTER(
            Dosing, 
            Dosing[Study] = 'Adverse Event'[Study] &&
            Dosing[Subject] = 'Adverse Event'[Subject] &&
            Dosing[Collection Time] <= 'Adverse Event'[Start Time] && 
            'Adverse Event'[Is this a Pre-dose AE?] = "No"
        )
    )

     

    This was done quickly, may need to tweak the calculation a bit.

     

2 Replies

  • Hi Christian,

     

    Not sure if you want Power Query or DAX or what the relationships in your model look like, but as a first draft, DAX, try this...

     

     

    First Dosing for Subject = 
    CALCULATE(
        MIN(Dosing[Collection Time]), 
        FILTER(
            Dosing, 
            Dosing[Study] = 'Adverse Event'[Study] &&
            Dosing[Subject] = 'Adverse Event'[Subject] &&
            'Adverse Event'[Is this a Pre-dose AE?] = "No"
        )
    )

     

    Last Dosing Before AE = 
    CALCULATE(
        MAX(Dosing[Collection Time]), 
        FILTER(
            Dosing, 
            Dosing[Study] = 'Adverse Event'[Study] &&
            Dosing[Subject] = 'Adverse Event'[Subject] &&
            Dosing[Collection Time] <= 'Adverse Event'[Start Time] && 
            'Adverse Event'[Is this a Pre-dose AE?] = "No"
        )
    )

     

    This was done quickly, may need to tweak the calculation a bit.