# Apply variable values in filter with entitySelector

**URL:** <https://community.dynatrace.com/t/apply-variable-values-in-filter-with-entityselector/40707>\
**Category:** DQL\
**Tags:** dql, entity-selector, dashboards\
**Created:** [July 14, 2023, 3:26pm UTC](https://community.dynatrace.com/t/apply-variable-values-in-filter-with-entityselector/40707 "2023-07-14T15:26:48Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![mgome](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@mgome](https://community.dynatrace.com/u/mgome)\
**Post date:** [March 27, 2025, 6:37pm UTC](https://community.dynatrace.com/t/apply-variable-values-in-filter-with-entityselector/40707/9 "2025-03-27T18:37:45Z")

</div>

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.

```python
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. &nbsp;The first argument is the beginning of the entity selector in quotes. &nbsp;The second argument is the variable converted to a string. &nbsp;The last argument is a quoted close&nbsp;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.

---

_[View the full topic](https://community.dynatrace.com/t/apply-variable-values-in-filter-with-entityselector/40707)._
