Get the most recent of two events

I’m trying to build a query that will show a table of devices, and the most recent toggle state for each device. So in this case I believe the Facet would be device_id and I’m trying to display next to the ID the most recent toggle event between ‘toggle_on’ and ‘toggle_off’

Is there a good way to accomplish this?

Hi, @michael.chovan: Toggle_on and toggle_off are separate events? If so, I don’t think it is possible. If you had a single Toggle event with a currentState attribute, you could use latest(currentState) to get the most recent state.

Yeah they are, but your solution makes sense-- let me see if I can accomplish that.

Oh correction-- they are the same event, Toggle_on and Toggle_off are separate actions

I am not sure what “action” means in this context. Are they two possible values for an event attribute?

Using my previous example of a Toggle event with a currentState attribute, you could use a query like this:

SELECT latest(currentState) FROM Toggle FACET deviceId

See if you can adapt that to your data.

1 Like