I want to revisit the original question because filtering in the timeseries query is faster than filtering after the query. In order to use a variable as part of an entity selector filter in a timeseries query, you need to use classicEntitySelector, concat and toString.
timeseries cpu=avg(dt.host.cpu.usage),
filter:in(dt.entity.host,
classicEntitySelector(concat("type(host),tag(Environment:",
toString($Environment),
")")
)
),
by:{dt.entity.host}
| sort arrayAvg(cpu) desc
| limit 20
Breaking down the filter, there’s an embedded concat in the classicEntitySelector call with three arguments. The first argument is the beginning of the entity selector in quotes. The second argument is the variable converted to a string. The last argument is a quoted close parentheses to end the entity selector.
Anything you can to do reduce the amount of data returned in the timeseries query will make tiles in dashboards load faster.