Get value of latest entry even if value is null

Hello,

I want to display a custom timestamp of the oldest entry in a database table.
Therefore, I repeatedly query the database and get the oldest creation timestamp.
I then push it as a custom value to New Relic. In my dashboard I want to display the oldest value from the database. Meaning if there are no values anymore in table I report my custom timestamp as null (or do the event without the attribute) to New Relic and in the dashboard I want to see the “No values” result or something similar.

I start on that using the latest function but that returns of course the latest existing value from my custom metrics.
Is there a way to get the value of the latest entry of my custom metrics even if that has no value in it?

Thanks and best regards!

You should be able to pull the latest value even if it is null. The results will just show NULL

Either with

SELECT latest(myCustomAttribute) FROM myCustomEvent SINCE TODAY

For the oldest, you could try:

SELECT earliest(myCustomAttribute) FROM myCustomEvent SINCE TODAY

These will operate on the timestamps that the events came in. Not the earliest / latest value of your custom timestamp that you are sending.

For that you could try:

SELECT min(myCustomTimestamp) FROM myCustomEvent

or

SELECT max(myCustomTimestamp) FROM myCustomEvent

@RyanVeitch
I think I wasn’t that clear about my problem, so I will try it with this screenshot.


This would be my data. My goal is to get the value of the green box on the dashboard. Using latest I will get the latest “not null” value from the red box.

About my post with the screenshots:

You should be able to pull the latest value even if it is null. The results will just show NULL

This is in fact not what I experience in my trial.

I see - by switching to the raw JSON results view the values are recorded as NULL.

I think the issue here is that your custom attribute is formatted as a timestamp - so the chart builder is trying to render null as a timestamp and can’t - thus leading to the row being blank.

This may be expected when the formatter is used to display values differently to their raw data form. I’ll get a request filed for this to be updated to always show NULL when it is indeed reported as NULL. Rather than blanking the results when null is reported and can’t be reformatted as a timestamp.

1 Like