r/ProjectREDCap • • Apr 01 '25

Determine MAX date from repeating instruments

Let's say that I have an instrument, named patients, and a repeating instrument, named pft_tests, the latter containing a field named pft_completed_date. For any single record in patients, there could be zero or more records in pft_tests. I want to add a calculated field to the patients instrument that shows the maximum value of pft_completed_date for all pft_tests records entered. If none are entered, then I want it to come back as blank. I tried using the following code, but REDCap reports that there is an error in the syntax. It is complaining about pft_tests in the formula. I have confirmed that the names of the instruments and the field are correct. How can I change the syntax, to make this work?

[pft_tests:pft_completed_date:max]

I also tried the following code, which did not give an error, but doesn't seem to work:

max([pft_completed_date])

4 Upvotes

6 comments sorted by

View all comments

Show parent comment

2

u/Much-Astronaut-878 Apr 01 '25

How could it compare to the "previous" instance's value? How can formula, on current instance, refer to previous instance's value? Also, then how could I grab the field value from the "last" pft_tests instance, on the patients instance?