Getting latest (by date) item from a relation - Using single value column

I have a relation bringing multiple results. And a single value column pulling off this relation column. I need the single value column to show the last item in the relation based on timestamp.

I’ve read through lots of help on the community and there is many mentions of using single value column “last” function to bring in the LAST date entry of the relation item.

I have an entry date column in my relation, but the relation results are just randomly sorting the items, not based on the entry date. So when I use the “last” function for single value it literally pulls in the last record (which is just randomly sorted). So not actually the last date option.

Is this a bug? Not sure why it’s not working as it seems quite basic to me…

Send help :slight_smile:

What you want is “Latest”, not “Last”

If you don’t see Latest as an option, that would suggest that your source column is not properly configured as a date/time type.

1 Like

Thanks for your reply, but I need a unique “latest” item depending on the record.

I have a table which is orders, these orders are populated by a single product (options held in another table). The user can browse the products and select only one, when they select one it adds a row to a middleman table which connects the product data to the order data (by capturing and splitting the url).

They are then able to checkout, but say they are like oh actually I want to go back and change my product. They then select another product and it adds another row to the middleman table, capturing the date and time as well. So now this order technically has two rows in the middleman table. I use a relation to gather all rows that match the order id, and I want the latest (by date) to show as a single value as the final selected option.

I’m not sure if it’s possible to delete the original row and replace it, so there is only one record for that order id. Or how I can ensure the order holds the last selected product by date.

The answer is the same: use Rollup → Latest via the relation.

Ok amazing that works, can I show the image and name for that item as well?

You would need to use the returned date/time to create a Single Relation to the line item (matching the date/times), and then you could use lookups via that relation to get name and image.

Ok cool, but if someone else also clicked a product at the exact same second (hypothetically) then it could get confused between the correct order id? If the relation is based solely on the exact date and time match.

Dates/times stored in Glide include seconds and milliseconds under the hood. It would be extremely unlikely to have two identical timestamps, probably close enough to impossible to be not worth worrying about.

1 Like

Amazing! Thank you for your time and help, Darren! We will put this to the test :wink:

What I would do is use a template column to join the order Id and the latest date together. Do that in both tables, and then use the template columns for the relation.

3 Likes

Boom :boom: thank you! This is the cherry on top

1 Like