# How to make a new Timeseries by calculating data from 2 individual Timeseries?

**URL:** <https://community.dynatrace.com/t/how-to-make-a-new-timeseries-by-calculating-data-from-2-individual-timeseries/56284>\
**Category:** DQL\
**Tags:** dql, timeseries\
**Created:** [June 25, 2026, 9:54am UTC](https://community.dynatrace.com/t/how-to-make-a-new-timeseries-by-calculating-data-from-2-individual-timeseries/56284 "2026-06-25T09:54:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hillman](https://avatars.discourse-cdn.com/v4/letter/h/439d5e/32.png) [@Hillman](https://community.dynatrace.com/u/Hillman)\
**Post date:** [June 25, 2026, 9:54am UTC](https://community.dynatrace.com/t/how-to-make-a-new-timeseries-by-calculating-data-from-2-individual-timeseries/56284/1 "2026-06-25T09:54:02Z")

</div>

As the PostgreSQL extension does not ingest the Cache Hit Ratio metrics, we have to do manual calculation with the following formula:

100 \* blocks\_hit / ( blocks\_hit + blocks\_read )

blocks\_hit and blocks\_read are 2 Timeseries and I want to use the above formula to calculate and make a new Timeseries for Cache Hit Ratio. Is it possible to do so?

---

<div class="post-metadata">

**Author:** ![dannemca](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/dannemca/32/7215_2.png) [@dannemca](https://community.dynatrace.com/u/dannemca)\
**Post date:** [June 25, 2026, 11:47am UTC](https://community.dynatrace.com/t/how-to-make-a-new-timeseries-by-calculating-data-from-2-individual-timeseries/56284/2 "2026-06-25T11:47:56Z")

</div>

Yes, it is possible.

For example, I will paste here a DQL that sums up the values from %CPU and %MemUsage, using the lookup command ,&nbsp;[DQL correlation and join commands — Dynatrace Docs](https://docs.dynatrace.com/docs/platform/grail/dynatrace-query-language/commands/correlation-and-join-commands#lookup)

```markup
timeseries { mem = avg(dt.host.memory.usage) }, by: { dt.entity.host }
| fieldsAdd dt.entity.host.name = entityName(dt.entity.host)
| lookup [timeseries { cpu = avg(dt.host.cpu.usage) }, by: { dt.entity.host }
| fieldsAdd dt.entity.host.name = entityName(dt.entity.host)], sourceField:dt.entity.host, lookupField:dt.entity.host
| fieldsAdd cpu_mem = mem[] + lookup.cpu[]

```

I am using the host name as matching field, so we calculate the right value for the right entity.

You can remove the original fields at the end, or configure it on visualization settings.

Try with your metrics and let us know.

---

<div class="post-metadata">

**Author:** ![krzysztof\_hoja](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/krzysztof_hoja/32/34625_2.png) [@krzysztof\_hoja](https://community.dynatrace.com/u/krzysztof_hoja)\
**Post date:** [June 25, 2026, 1:44pm UTC](https://community.dynatrace.com/t/how-to-make-a-new-timeseries-by-calculating-data-from-2-individual-timeseries/56284/3 "2026-06-25T13:44:31Z")

</div>

In this case it can be simplified and _ **lookup** _ is not needed. With _ **timeseries** _ command you can retrieve multiple metrics in single command:

```markup
timeseries { mem = avg(dt.host.memory.usage), cpu = avg(dt.host.cpu.usage) }, by: { dt.entity.host }, union: true
| fieldsAdd dt.entity.host.name = entityName(dt.entity.host)
| fieldsAdd cpu_mem = mem[] + cpu[]

```

---

<div class="post-metadata">

**Author:** ![Hillman](https://avatars.discourse-cdn.com/v4/letter/h/439d5e/32.png) [@Hillman](https://community.dynatrace.com/u/Hillman)\
**Post date:** [June 26, 2026, 6:56am UTC](https://community.dynatrace.com/t/how-to-make-a-new-timeseries-by-calculating-data-from-2-individual-timeseries/56284/4 "2026-06-26T06:56:05Z")

</div>

Thank you&nbsp;[@krzysztof\_hoja](https://community.dynatrace.com/user/25373)&nbsp;, [@dannemca](https://community.dynatrace.com/user/18264)&nbsp;, I am able to create a timeseries with the cache hit ratio!

I have got one more question. When I try to create a Single Value chart with the following DQL.

```markup
timeseries { blocks_read = avg(postgres.blks_read.count), blocks_hit = avg(postgres.blks_hit.count) }, by: { device.name, database }, union: true
| fieldsAdd cache_hit_ratio = (100 * blocks_hit[] / (blocks_read[] + blocks_hit[]))
| fieldsAdd `Cache hit ratio` = arrayAvg(cache_hit_ratio)
| fieldsRemove interval

```

I have found the sparkline cannot be displayed if I assign the timeseries cache\_hit\_ratio as the sparkline. Do you have any idea why does that happen?

 ![Hillman_0-1782456924091.png](https://global.discourse-cdn.com/dynatrace/original/3X/1/9/19c397700d08d20eecab460a3c023ceaaacb7b86.png)

---

<div class="post-metadata">

**Author:** ![dannemca](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/dannemca/32/7215_2.png) [@dannemca](https://community.dynatrace.com/u/dannemca)\
**Post date:** [June 26, 2026, 2:26pm UTC](https://community.dynatrace.com/t/how-to-make-a-new-timeseries-by-calculating-data-from-2-individual-timeseries/56284/5 "2026-06-26T14:26:07Z")

</div>

That’s because you removed the interval field. Comment/remove the last line and test again.

---

<div class="post-metadata">

**Author:** ![Hillman](https://avatars.discourse-cdn.com/v4/letter/h/439d5e/32.png) [@Hillman](https://community.dynatrace.com/u/Hillman)\
**Post date:** [July 2, 2026, 3:33am UTC](https://community.dynatrace.com/t/how-to-make-a-new-timeseries-by-calculating-data-from-2-individual-timeseries/56284/6 "2026-07-02T03:33:08Z")

</div>

I have comment that line and it can show up now. Thank you for your help!
