NRQL to get latest event for dashboard

Here is my scenario,

We send events to NR with different details, for example,
8 AM I get,
event 1:
{
id: 1234,
event_type: sample_event,
name : ABC,
value_1: 5,
value_2: 4
}
event 2:
{
id: 1443,
event_type: sample_event,
name : ewq,
value_1: 40,
value_2: 10
}

2PM I get,
event 1:
{
id: 1234,
event_type: sample_event,
name : ABC,
value_1: 50,
value_2: 2
}
event 2:
{
id: 1443,
event_type: sample_event,
name : ewq,
value_1: 4,
value_2: 10
}

I need to show the sum of value_1 and value_2 for events for the latest,

from Log select sum(value_1) as ‘Total Value 1’, sum(value_2) as ‘Total Value 2’ where event_type=‘sample_event’.

this would return value based on the duration i mention in the query for instance if i run this at 3PM with last 2 hours i get the sum of values that are sent at 2PM, if i change it to last 24hours i get sum of all the event in last 24 hours( i know this is pretty straight forward).

But once the new event is published for this widget in dashboard i always want to show the detail of latest event.

I do use it historical information to create line chart, but when it comes to summary i need to show the latest event detail only.

Appreciate the comments and suggestion for this. Thanks.

Hi, @vicky.mkce: Does this work?

SELECT latest(value_1) + latest(value_2) FROM YourEvent

Thanks @philweber I apologize if the question was not clear.

Correct me if I’m wrong, I think latest keyword give me the last event that is published the attribute and its value, in the example if i use latest(value_1) keyword it would give me the value_1 of event 2 at 2PM which is 4 what i want is sum of event 1 and event 2’s value_1 which is 54.

latest keyword not filtering latest unique events, it just look for latest event and cannot use unique keyword in filter condition.

Ah, sorry, I misunderstood. I do not know of any way to do what you are asking.