# Metric Timeseries with Array Dimension

**URL:** <https://community.dynatrace.com/t/metric-timeseries-with-array-dimension/48544>\
**Category:** DQL\
**Tags:** dql, dynatrace-managed, logs\
**Created:** [October 24, 2024, 1:43pm UTC](https://community.dynatrace.com/t/metric-timeseries-with-array-dimension/48544 "2024-10-24T13:43:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![StrangerThing](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/strangerthing/32/12182_2.png) [@StrangerThing](https://community.dynatrace.com/u/StrangerThing)\
**Post date:** [October 24, 2024, 1:43pm UTC](https://community.dynatrace.com/t/metric-timeseries-with-array-dimension/48544/1 "2024-10-24T13:43:22Z")

</div>

I have a log metric that has a dimension of the array type. When I put this metric in a timeseries, I split by this dimension, however it collects the entire array when doing so, instead of each element. I tried using the expand command and then summarize to do some counting on the elements, but in doing so I lose my timeseries data. When I try to put this back in a timeseries with the makeTimeseries command, I get an error about the time.

I know I can do what I want by querying the raw logs and using makeTimeseries, which was my workaround for this. But what I’d like to know (mostly because I’m curious) is if there’s a way to do what I’m talking about and I just couldn’t figure it out. Here’s the queries below.

Metric query that I’d like to get a timeseries of each element:

```markup
timeseries sum(log.metric), by:{dimension}
| expand dimension
| summarize count(), by:{dimension}

```

Log query I’ve used as a workaround:

```markup
fetch logs
| filter dt.system.bucket == "my_bucket"
| filter isNotNull(dimension)
| expand dimension
| makeTimeseries count(), by:{dimension}

```

---

<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:** [October 24, 2024, 8:07pm UTC](https://community.dynatrace.com/t/metric-timeseries-with-array-dimension/48544/2 "2024-10-24T20:07:53Z")

</div>

When you do this:

```markup
| summarize count(), by:{dimension}

```

the only fields which survive directly such operation are the ones listed in _ **by:** _ parameter and these created by expressions listed after _ **summarize** _. So there is no possibility to put anything back.

I prepared some example data which create timeseries resembling what you have :

```markup
data 
  record(timestamp=now(), v=1, dimension=array("a","b")),
  record(timestamp=now()-1m, v=2, dimension=array("a","b")),

  record(timestamp=now(), v=3, dimension=array("b")),  
  record(timestamp=now()-1m, v=1, dimension=array("b")),

  record(timestamp=now(), v=4, dimension=array("c")),  
  record(timestamp=now()-1m, v=2, dimension=array("c")),
  record(timestamp=now()-2m, v=2, dimension=array("c")),

  record(timestamp=now(), v=1, dimension=array("c","b")),
  record(timestamp=now()-1m, v=2, dimension=array("c","b")),
  record(timestamp=now()-2m, v=2, dimension=array("c","b"))

| makeTimeseries {log.metric=sum(v)}, by:{dimension}, from: now()-5m, interval: 1m

```

 ![krzysztof_hoja_2-1729800062796.png](https://global.discourse-cdn.com/dynatrace/original/2X/7/74abde1df438839879acdf16250a74b6ae6bea5a.png)

As I understand the goal is to count over time how many times each element of array being dimension was present in data. This query is calculating this:

```markup
data 
  record(timestamp=now(), v=1, dimension=array("a","b")),
  record(timestamp=now()-1m, v=2, dimension=array("a","b")),

  record(timestamp=now(), v=3, dimension=array("b")),  
  record(timestamp=now()-1m, v=1, dimension=array("b")),

  record(timestamp=now(), v=4, dimension=array("c")),  
  record(timestamp=now()-1m, v=2, dimension=array("c")),
  record(timestamp=now()-2m, v=2, dimension=array("c")),

  record(timestamp=now(), v=1, dimension=array("c","b")),
  record(timestamp=now()-1m, v=2, dimension=array("c","b")),
  record(timestamp=now()-2m, v=2, dimension=array("c","b"))

| makeTimeseries {log.metric=sum(v), timestamp=start()}, by:{dimension}, from: now()-5m, interval: 1m

| expand dimension
| fieldsAdd d=record(timestamp=timestamp[], log.metric=log.metric[])
| expand d
| filterOut isNull(d[log.metric])

| makeTimeseries count(), by: {dimension}, time:d[timestamp], from:now()-5m, interval: 1m

```

In order to have time we need to use _**start()**_ function which creates timeseries with timestamps and associate each datapoint with timestamp. I assumed that you do not want to count when metric value was null (data not present)

Result looks like this:

 ![krzysztof_hoja_3-1729800364505.png](https://global.discourse-cdn.com/dynatrace/original/3X/9/4/94f18f525d39ef1170cef0472a3526ac5584ce58.png)

I hope it helps

Kris

---

<div class="post-metadata">

**Author:** ![StrangerThing](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/strangerthing/32/12182_2.png) [@StrangerThing](https://community.dynatrace.com/u/StrangerThing)\
**Post date:** [October 25, 2024, 3:16pm UTC](https://community.dynatrace.com/t/metric-timeseries-with-array-dimension/48544/3 "2024-10-25T15:16:05Z")

</div>

This is exactly what I wanted. Thanks so much for the help!
