# DQL - timeseries on a dashboard with different timeseries data being shown depending on variable selection

**URL:** <https://community.dynatrace.com/t/dql-timeseries-on-a-dashboard-with-different-timeseries-data-being-shown-depending-on-variable-selection/52551>\
**Category:** DQL\
**Tags:** dql, dashboards, timeseries\
**Created:** [July 18, 2025, 4:21pm UTC](https://community.dynatrace.com/t/dql-timeseries-on-a-dashboard-with-different-timeseries-data-being-shown-depending-on-variable-selection/52551 "2025-07-18T16:21:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![CSBee](https://avatars.discourse-cdn.com/v4/letter/c/7c8e57/32.png) [@CSBee](https://community.dynatrace.com/u/CSBee)\
**Post date:** [July 18, 2025, 4:21pm UTC](https://community.dynatrace.com/t/dql-timeseries-on-a-dashboard-with-different-timeseries-data-being-shown-depending-on-variable-selection/52551/1 "2025-07-18T16:21:35Z")

</div>

Hello, I am having issues with a Dashboard / DQL query.

I have a variable on my dashboard called $Measurement and depending on what that shows I either want to see timeseries data for P90 or Average on my graph.&nbsp; I have tried the below:

timeseries  
value.Avg = percentile(dt.service.request.response\_time, 50, default:0), interval:10m, nonempty:true,  
value.P90 = percentile(dt.service.request.response\_time, 90, default:0),  
by: { dt.entity.service },  
from: now()-1d,  
to: now()  
| fieldsAdd ServiceName = entityName(dt.entity.service)  
| fieldsAdd Data = if($Measurement==“Average”, value.Avg, else: value.P90)  
| fieldsKeep timeframe, interval, Data, ServiceName

Which gives me charting, but the numbers are wrong, as in it doesn’t seem to know that Data is nanoseconds, so it plots it as M instead of the usual default S. I have tried making the value.Avg in to seconds as it is assigned to Data, but that does not work, as I am guessing that it is the default data type of Data hasn’t taken on the timeseries format.

Any ideas please?

Or maybe I am going about this the wrong way entirely!

I have shown how the data plots on the graphs, if I do the value.Avg and value.P90 it is the bottom chart, if I just do the Data, it is the top one

 ![Screenshot 2025-07-18 171931.gif](https://global.discourse-cdn.com/dynatrace/original/2X/c/cd4ef19895652947408f6f79f6d1f7b5b93fea91.gif)

---

<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:** [July 21, 2025, 7:04pm UTC](https://community.dynatrace.com/t/dql-timeseries-on-a-dashboard-with-different-timeseries-data-being-shown-depending-on-variable-selection/52551/2 "2025-07-21T19:04:01Z")

</div>

I believe you are running into this issue because the fieldsAdd command is not keeping the data formatting. There’s an opportunity here to use the variable directly with a fieldsKeep command to control which fields are retained.

For illustrative purposes, let us start with a variable called $series, with values of ‘median’ and ‘p90’.

 ![marco_irmer_0-1753124559839.png](https://global.discourse-cdn.com/dynatrace/original/2X/c/ca94a12c229ad85c1cc743bda39176d45e7193d0.png)

The next step is to alter our DQL query slightly, so that the series names match the variable values. Once this is done, we can substitute the variable value right in the fieldsKeep command, resulting in the following DQL:

```javascript
timeseries
p50 = percentile(dt.service.request.response_time, 50, default:0), interval:10m, nonempty:true,
p90 = percentile(dt.service.request.response_time, 90, default:0),
by: { dt.entity.service },
from: now()-1d,
to: now()
| fieldsAdd ServiceName = entityName(dt.entity.service)
| fieldsKeep timeframe, interval, ServiceName, $series

```

I hope this helps.

---

<div class="post-metadata">

**Author:** ![csb](https://avatars.discourse-cdn.com/v4/letter/c/b5a626/32.png) [@csb](https://community.dynatrace.com/u/csb)\
**Post date:** [July 22, 2025, 8:27am UTC](https://community.dynatrace.com/t/dql-timeseries-on-a-dashboard-with-different-timeseries-data-being-shown-depending-on-variable-selection/52551/3 "2025-07-22T08:27:51Z")

</div>

Thank you so much, that works perfectly
