# Querying services related to an entity

**URL:** <https://community.dynatrace.com/t/querying-services-related-to-an-entity/47960>\
**Category:** DQL\
**Tags:** dql, dynatrace-managed, logs\
**Created:** [September 24, 2024, 8:24pm UTC](https://community.dynatrace.com/t/querying-services-related-to-an-entity/47960 "2024-09-24T20:24:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DamianJankowski](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/damianjankowski/32/10540_2.png) [@DamianJankowski](https://community.dynatrace.com/u/DamianJankowski)\
**Post date:** [September 24, 2024, 8:24pm UTC](https://community.dynatrace.com/t/querying-services-related-to-an-entity/47960/1 "2024-09-24T20:24:33Z")

</div>

I want to create a line chart that displays the response time metric for a selected service. I need it to be dynamic, so I’ve set up a variable. Here’s the variable definition:

```cpp
fetch dt.entity.service
| fields entity.name

```

When the user selects an entity.name, the line chart should update and display the corresponding metric for that service.

I’ve tried the following query:

```python
timeseries response_time = percentile(dt.service.request.response_time, 50),
by: { dt.entity.service },
filter: { in(id, classicEntitySelector("type(service),fromRelationship.IS_SERVICE_OF(type(CLOUD_APPLICATION),entityName.equals($Entity'))")) }

```

---

<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:** [September 26, 2024, 7:50am UTC](https://community.dynatrace.com/t/querying-services-related-to-an-entity/47960/2 "2024-09-26T07:50:54Z")

</div>

I see few problem with this query:

- $Entity is string variable, so it should be explicitly concatenated with the rest of entity select expressions
- If you want to filter by service name (variable values query suggests it), entity selector is incorrect
- the identification of the service id in metric is&nbsp;dt.entity.service, so it should be used in _**in()**_ filtering expression

This query should work better:

```markup
timeseries response_time = percentile(dt.service.request.response_time, 50),
by: { dt.entity.service },
filter: { in(dt.entity.service, classicEntitySelector(concat("type(service),entityName.equals(",$Entity,")"))) }

```

Result looks like this:

 ![krzysztof_hoja_0-1727337003922.png](https://global.discourse-cdn.com/dynatrace/original/3X/4/c/4cdd84dbaa51b0cc77b47a51585b7bb97bb6fa49.png)

---

<div class="post-metadata">

**Author:** ![DamianJankowski](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/damianjankowski/32/10540_2.png) [@DamianJankowski](https://community.dynatrace.com/u/DamianJankowski)\
**Post date:** [September 28, 2024, 5:27pm UTC](https://community.dynatrace.com/t/querying-services-related-to-an-entity/47960/3 "2024-09-28T17:27:56Z")

</div>

yep, thanks a lot 🙂 I finally figured it out.
