Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Closest Matching of Dates

Featured Replies

Please can beg for some FM18 help! I have 2 tables TPTable::date that is linked to HLTable:HL::date. I need to automate the look up of 2000 TPTable records to the closest match HLDate (80 records). I know there must be a way, but it has alluded me thus far! Thanks

Greetings - need some more context what is unique in each table that could be used as a match to lookup data?

you could use multiple predicates in the relationship or concatenate several fields together to make a unique key to lookup data. 

 

  • Author

Thanks for prompt reply. I have a unique ID for each table. __TPRecordID and __HLRecordID, does that help?

If you define a relationship between the two tables matching on the date field, you can use a calculation in the first table to find the closest date in the second table: use the LookupNext() function to find the nearest date before the given date; use the same function to find the nearest date after the given date; compare the differences and select the date with the smaller one.

 

  • Author

Let me try that again. I had a field cLookup_higher in my TPTable that auto calculates:

LookIpNext(HlTable::HLdate;Higher). The relationship between HLTable and TPTable is HLdate < date AND HLdate >= date. Unfortunately this did not yield a result... HLdate = date didn’t work either. 

I am afraid I am not able to follow your description. Does the attached demo file do what you expect?

 

ClosestDate.fmp12

  • Author

Thank you thank you thank you! It does. It was my relationships that was at fault. 😊

  • 2 weeks later...
  • Author

Hi "Comment" - sorry to bother again. Closest Date not working after I changed my fields . I have replicated your relationships: closestdate = date (in my case cLookUp = HLDate) and it always returns original HLDate. Simplified I have three relationships between tables:
HLTable - TPTable -> HLID_pk = HLID_fk  this is my link to create TPTable from HLTable where I add various dates to my HLDate to derive my new cTPDate. To recap I have the original date from Excel import, HLDate, I bring HLDate to TPTable using a script and the add various dates to HLDate in TPTable to give me my cTPDate

HLTable_lookup - TPTable -> HLDate = cLookup

HLTable_date - TPTable -> HLDate = HLDate (replicating your model), it just returns my original HLDate. Also tried HLDate = cTPDate, which doesn't work same thing - not the closest match.

cLookUp is strictly your calculation whether I reference to HLTable::HLDate  it just returns my original HLDate. If I reference to HLTable_date::HLDate,  it still returns my original HLDate- not the closest match. If I reference to HLTable_lookup::HLDate or  it just crashes.

Any ideas, thanks

I am afraid I couldn't debug your file without seeing it even if I wanted to... 🙃

 

 

  • Author

Thanks anyway - I shall rebuild the tables and see what went wrong.

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.