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 popu...
  • KNP's avatar
    10 months ago

    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.