Forum Discussion

Mythicos's avatar
Mythicos
Frequent Visitor
2 years ago
Solved

Find result nearest a target date

Hello,   I have a table that includes the following data about transplants: ID of transplant Date of transplant One or more laboratory results (with the lab date) Table looks like this:   ...
  • Sahir_Maharaj's avatar
    2 years ago

    Hello Mythicos,

     

    Can you please try this approach:

     

    1. Calculate the Target Date

    Target Date = [Dt GRF] + 100
    

    2. Difference from Target Date

    Diff Labo #1 = ABS(DATEDIFF([Target Date], [Dt Labo #1], DAY))
    Diff Labo #2 = IF(NOT(ISBLANK([Dt Labo #2])), ABS(DATEDIFF([Target Date], [Dt Labo #2], DAY)), BLANK())
    Diff Labo #3 = IF(NOT(ISBLANK([Dt Labo #3])), ABS(DATEDIFF([Target Date], [Dt Labo #3], DAY)), BLANK())
    

    3. Nearest Lab Result

    Day 100 MLL = 
    SWITCH(
        TRUE(),
        [Diff Labo #1] <= [Diff Labo #2] || ISBLANK([Diff Labo #2]) && [Diff Labo #1] <= [Diff Labo #3] || ISBLANK([Diff Labo #3]), [MLL #1],
        [Diff Labo #2] <= [Diff Labo #1] || ISBLANK([Diff Labo #1]) && [Diff Labo #2] <= [Diff Labo #3] || ISBLANK([Diff Labo #3]), [MLL #2],
        [MLL #3]
    )
    

    Hope this helps!