cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

CSBee
Newcomer_

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.  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

 

2 REPLIES 2

marco_irmer
Champion

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

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:

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.

Thank you so much, that works perfectly

Featured Posts