# plot linechart from log metric with countDistinctExact

**URL:** <https://community.dynatrace.com/t/plot-linechart-from-log-metric-with-countdistinctexact/46670>\
**Category:** DQL\
**Tags:** dql, dynatrace-managed\
**Created:** [July 18, 2024, 8:21am UTC](https://community.dynatrace.com/t/plot-linechart-from-log-metric-with-countdistinctexact/46670 "2024-07-18T08:21:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_r\_k](https://avatars.discourse-cdn.com/v4/letter/_/3d9bf3/32.png) [@\_r\_k](https://community.dynatrace.com/u/_r_k)\
**Post date:** [July 18, 2024, 8:21am UTC](https://community.dynatrace.com/t/plot-linechart-from-log-metric-with-countdistinctexact/46670/1 "2024-07-18T08:21:03Z")

</div>

I cannot figure out how to introduce custom aggregation to log metrics for dashboarding with dynamic timeframe (plot linechart) use

for example&nbsp;_countDistinctExact_

_timeseries_&nbsp;_log\_custom\_metric\_value = count(log.custom.metric),_&nbsp;_by: {dimension}_

_| summarize {no\_of\_uni=countDistinctExact(log\_custom\_metric\_value[])}, by:{interval, timeframe}_

is returning:

_This aggregation function currently doesn’t support iterative expressions._

is there way how to introduce custom aggregation (for example with summarization) for metrics ?thank youR

---

<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:** [July 19, 2024, 11:25am UTC](https://community.dynatrace.com/t/plot-linechart-from-log-metric-with-countdistinctexact/46670/2 "2024-07-19T11:25:43Z")

</div>

It’s true that some aggregation functions are not supported in _ **makeTimeseries** _ command or they do not work for arrays (iterative expressions) in _ **summarize** _ but you can always breakdown array into single rows and do what it needed using _ **summarize** _ and all aggregation functions on any fields and expressions.

Here is example on one of my metrics from log:

```markup
timeseries {cnt=count(log.aws.vpc.bytes), timestamp=start()}, by:{vpc_id}, interval:1m
| fieldsAdd d=record(cnt=cnt[], timestamp=timestamp[])
| expand d 
| summarize {cnt=countDistinctExact(d[cnt])}, by: {timestamp=d[timestamp]}
| makeTimeseries cnt=max(cnt), interval:1m

```

First step is to build array of pairs: time and metric value. The next one is to **expand** it. At this moment each datapoint is individual row and you can apply any aggregation. To get it back as array using _ **makeTimeseries** _ is needed, but as before this step you have each value already in its final form, you can use any aggregation function as this will be 1 filed in on record to 1 element in array conversion (I used max).

I used your query as input where you attempt to calculate distinct count of metric values for each interval.

I hope it helps

Kris
