Get last item in GroupBy in a Do a Search for

To all,

I have a situation where I need to retrieve the last entered status for each service ticket in a Do a Search for operation.

Note: The statuses are then going to be counted so that I can create a chart of what’s open, in progress, and closed for the day.

If I were in PostgreSQL, I’d do something like this where I can do a distinct record of ticket/status for a dataset that is sorted by ticket/created date desc:
SELECT DISTINCT ON (ticket)
ticket,
data->‘status’ AS status
FROM
ServiceLog
ORDER BY
ticket,
CreateDate DESC;

I see the :Unique Elements operator but it only appears to work on a single column. I’m not seeing a clear path on how to do this in Bubble. My Google-fu is failing me miserably as I’ve not found any handy solutions either.

Any pointers and/or suggestions welcome!

Ok, came up with a solution that seems to work and makes the repeating group filter really fast. I’m documenting it here so that the next time I need it, I’ll know what I did last time. :slight_smile:

What I know when creating a new status.

  1. I know when the last status is for a given ticket when it’s entered
  2. I also know the ticket number to which the status is attached

So, I added a Last Entry Yes/No flag column to Status data type that I used to denote the latest for a given ticket. I also use that same column to filter on within the repeating group.

In the new status popup, when you enter a new status and click Save, the workflow

  1. Queries the statuses to find the record equal to Current Ticket and LastRecord = Yes
  2. It updates the value of the previous latest entry to No
  3. It creates the new thing with a value of Yes.

Not as elegant as I’d like but it works and having to retrieve only one record during an event that happens sporadically should be ok performance wise. Hopefully this makes sense to others.