# Return Last Known Value in Time-Series Using DQL makeTimeseries

**URL:** <https://community.dynatrace.com/t/return-last-known-value-in-time-series-using-dql-maketimeseries/50355>\
**Category:** DQL\
**Tags:** dql, timeseries, logs\
**Created:** [February 20, 2025, 9:05am UTC](https://community.dynatrace.com/t/return-last-known-value-in-time-series-using-dql-maketimeseries/50355 "2025-02-20T09:05:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dekidekide](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/dekidekide/32/35244_2.png) [@dekidekide](https://community.dynatrace.com/u/dekidekide)\
**Post date:** [February 20, 2025, 9:05am UTC](https://community.dynatrace.com/t/return-last-known-value-in-time-series-using-dql-maketimeseries/50355/1 "2025-02-20T09:05:06Z")

</div>

Hi,

I have a data/logs for job run status, which logs records for “Success” or “Fail” each run - job runs anytime base on schedule (e.i. 1-3 times a day and/or can be run manually). i’m tying to use makeTimeseries to capture alerts for Fail runs, but due to the nature of job run, there would be timeseries that won’t have data or NULL (e.i. “_| makeTimeseries countIf(status==“Fail”), interval: 1m, by: {task\_name}_” \>\> count(): 0, null, null, 1, null, null, null, 0, null, null … ) .. **1 = Fail, 0 = Success, null = no data.**

Is there a way in makeTimeseries where if the result of the count is null, set/change null with the “Last Known Value” from the series? so if the timeseries result is like this “count(): 0, **null, null,** 1, null, null, null, 0, **null, null,** …” i would like it to be changes like this “count(): 0, **0, 0** , 1, **1, 1, 1** , 0, **0, 0** , …”. using **default:0** won’t work in my case as it will also convert all “nulls” after value “1” to zero.

Thanks!

---

<div class="post-metadata">

**Author:** ![asamay](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/asamay/32/35909_2.png) [@asamay](https://community.dynatrace.com/u/asamay)\
**Post date:** [February 20, 2025, 5:53pm UTC](https://community.dynatrace.com/t/return-last-known-value-in-time-series-using-dql-maketimeseries/50355/2 "2025-02-20T17:53:06Z")

</div>

Hey,

Would doing a coalesce() funtion work for you in this scenario? Here are a couple of simple examples:

 ![asamay_0-1740073925383.png](https://global.discourse-cdn.com/dynatrace/original/3X/a/0/a05bbde229812ce2c3ec5c91d2d72f30250e1271.png)

Also here is the documentation on that function:&nbsp;[here](https://docs.dynatrace.com/docs/discover-dynatrace/references/dynatrace-query-language/functions/conditional-functions)

---

<div class="post-metadata">

**Author:** ![marco\_irmer](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/marco_irmer/32/3038_2.png) [@marco\_irmer](https://community.dynatrace.com/u/marco_irmer)\
**Post date:** [February 21, 2025, 11:10pm UTC](https://community.dynatrace.com/t/return-last-known-value-in-time-series-using-dql-maketimeseries/50355/3 "2025-02-21T23:10:18Z")

</div>

Have you considered using summarize() command rather than makeTimeSeries()?

You could combine it with&nbsp;the takeLast() function to show the most recent status:

_| summarize latestStatus = takeLast(status), by:{task\_name}_

Alternatively, you could also count up the number of observed log records by task\_name and status:

_| summarize count(), by: {task\_name, status}_

---

<div class="post-metadata">

**Author:** ![dekidekide](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/dekidekide/32/35244_2.png) [@dekidekide](https://community.dynatrace.com/u/dekidekide)\
**Post date:** [February 26, 2025, 1:48am UTC](https://community.dynatrace.com/t/return-last-known-value-in-time-series-using-dql-maketimeseries/50355/4 "2025-02-26T01:48:58Z")

</div>

thanks, asamay/marco. i actually gonna need it in time series as we will use davis ai/anomaly detector (which requires time series). i also tried&nbsp;coalesce() function but i can’t get the desired result.

---

<div class="post-metadata">

**Author:** ![marco\_irmer](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/marco_irmer/32/3038_2.png) [@marco\_irmer](https://community.dynatrace.com/u/marco_irmer)\
**Post date:** [March 6, 2025, 2:43pm UTC](https://community.dynatrace.com/t/return-last-known-value-in-time-series-using-dql-maketimeseries/50355/5 "2025-03-06T14:43:44Z")

</div>

I think I may have a hack you can use in certain circumstances, but it depends on two things:

1. Are 1 and 0 the only possible values for count() in your timeseries?
2. How many consecutive&nbsp;_null_ values occur in the data? Is it relatively few (10 or fewer) or do you have longer strings of _null_ values?

---

<div class="post-metadata">

**Author:** ![ADawson](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@ADawson](https://community.dynatrace.com/u/ADawson)\
**Post date:** [August 21, 2025, 5:35am UTC](https://community.dynatrace.com/t/return-last-known-value-in-time-series-using-dql-maketimeseries/50355/6 "2025-08-21T05:35:24Z")

</div>

I have a similar requirement and was wondering if a solution was ever found for this thread.

Requirement - Create a Davis detector that can raise/clear problems based on log entries that represent a bad/good states.

eg.

Raise problem when a log entry representing a bad state is seen in the logs.

Keep the problem alive&nbsp; &nbsp; &nbsp;(Bonus points for being able to keep the problem alive if its a long time between the bad log entry and the good log entry - hours/days)

Then clear the problem when a log entry representing a good state is seen in the log.

---

<div class="post-metadata">

**Author:** ![izabelarokita](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/izabelarokita/32/41812_2.png) [@izabelarokita](https://community.dynatrace.com/u/izabelarokita)\
**Post date:** [December 18, 2025, 12:30pm UTC](https://community.dynatrace.com/t/return-last-known-value-in-time-series-using-dql-maketimeseries/50355/7 "2025-12-18T12:30:30Z")

</div>

Hey&nbsp;[@dekidekide](https://community.dynatrace.com/user/86983)&nbsp;[@ADawson](https://community.dynatrace.com/user/64193)&nbsp;,  
I just wanted to check in and see if you still need help with this. If so, I’d be happy to look into it for you!&nbsp;:blush:  
Please let me know what works best for you.

---

<div class="post-metadata">

**Author:** ![ADawson](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@ADawson](https://community.dynatrace.com/u/ADawson)\
**Post date:** [December 18, 2025, 10:25pm UTC](https://community.dynatrace.com/t/return-last-known-value-in-time-series-using-dql-maketimeseries/50355/8 "2025-12-18T22:25:09Z")

</div>

Hi&nbsp;[@IzabelaRokita](https://community.dynatrace.com/user/67399)&nbsp;,

That would be great if you can provide some help.

We have a partial solution which is OK for&nbsp;short duration issues.

However, Im worried if we experience a longer issue such as on a Friday night where there may be no further log entries written for a few days. I would like the related problem to still be open on Monday if there is still an issue.

And I was hoping to avoid added complexities such as Business Events or Workflows as a work-around if possible.

Example of Davis Detector query -

fetch logs, bucket:{“Xlog”}  
| filter in(XeventId, {“DISCONNECTED”, “CONNECTED”})  
| fieldsAdd state = if(XeventId == “DISCONNECTED”, 1, else: if(XeventId == “CONNECTED”, 0, else: 2 ))  
| makeTimeseries count=count(default: 0), by:{dt.entity.host, host.name}, interval:1m
