If you have multiple deals associated with a person, it can be useful to have a single relationship that always points to the most recently created deal. This makes it much easier to build reports, formulas, and workflows without having to loop through every associated deal each time.
In this guide, we'll build a workflow that automatically updates a Most Recent Deal relationship whenever a person's associated deals change.
By storing the latest deal as its own relationship, you can easily:
For example, once the relationship exists you can create a formula like:
Most Recent Deal → Deal Status
to instantly show whether someone's latest opportunity is Open, Won or Lost.
Create a new relationship attribute on People called:
Most Recent Deal
This will store a single Deal record.
Create a new workflow.
Trigger:
Whenever a deal is added or removed from a person, the workflow will run.
Add an Execute Code block.
Pass in:
This will be an array of timestamps.
Use the following code:
The output is simply the newest Created at timestamp.
Next, add a Loop block.
Loop through:
Associated deals
This gives you access to each deal individually.
Inside the loop, add another Execute Code block.
Inputs:
createdAt Loop → Current Deal → Created at
mostRecentTimestamp Output from previous Execute Code
This simply returns true when the current deal is the newest one.
Check whether the Execute Code output is: true
If false, do nothing.
If true, continue to the next step.
Add an Update Record block.
Update:
Once the loop finds the matching deal, the relationship is updated.
Your Person records will now always contain a Most Recent Deal relationship.
Once populated, you can use it anywhere in Attio. For example:
This keeps your reporting and workflows much simpler, as you're always working with a single relationship rather than searching through every associated deal.
By matching the most recent deal timestamp to the Created at value of each deal within the loop, you can identify and associate the correct deal automatically. The same approach can also be used for Companies. Instead of storing the Most Recent Deal on a Person record, you can create a Most Recent Deal relationship on Companies and update it whenever associated deals change. This gives you an easy way to reference the latest deal for each company in reports, formulas, and workflows.