# Transposing the service ID with its name using DQL

**URL:** <https://community.dynatrace.com/t/transposing-the-service-id-with-its-name-using-dql/52215>\
**Category:** DQL\
**Tags:** dql, databases, services\
**Created:** [June 24, 2025, 9:00am UTC](https://community.dynatrace.com/t/transposing-the-service-id-with-its-name-using-dql/52215 "2025-06-24T09:00:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![walkadda](https://avatars.discourse-cdn.com/v4/letter/w/f1d935/32.png) [@walkadda](https://community.dynatrace.com/u/walkadda)\
**Post date:** [June 24, 2025, 9:00am UTC](https://community.dynatrace.com/t/transposing-the-service-id-with-its-name-using-dql/52215/1 "2025-06-24T09:00:34Z")

</div>

I have the following DQL query in my dashboard:

```markup
fetch dt.entity.host
| fields entity.name, runs
| fieldsFlatten runs
| filter in(runs.dt.entity.service, $services)
| fields entity.name, runs.dt.entity.service

```

The $services variable returns a list of service IDs, i.e “SERVICE-C1917273162D91”.

I would like the query to return a table of hosts and their corresponding services, using hostnames and service names. Here is an example of what I’m trying to achieve:

| hostname | service |
| --- | --- |
| server-01 | myservice, anotherservice, yetanotherservice |
| server-02 | myservice |
| server-03 | anotherservice, yetanotherotherservice |

But the actual result I get is:

| entity.name | runs.dt.entity.service |
| --- | --- |
| server-01 | SERVICE-C912138912D19, SERVICE-C1298314717J89, SERVICE-G821398124921B90 |
| server-02 | SERVICE-C1298314717J89 |
| server-03 | SERVICE-C1298314717J89, SERVICE-G821398124921B90 |

I have tried using the “lookup” function, but did not have any luck.

```markup
fetch dt.entity.service
| filter in(id, runs.dt.entity.host)
], lookupField:id, sourceField:runs.dt.entity.host

```

How can I display the&nbsp;name of the service&nbsp;in this table instead, whilst keeping the relationship between the host and its services?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![Akhil-Jayendran](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/akhil-jayendran/32/153_2.png) [@Akhil-Jayendran](https://community.dynatrace.com/u/Akhil-Jayendran)\
**Post date:** [June 24, 2025, 4:44pm UTC](https://community.dynatrace.com/t/transposing-the-service-id-with-its-name-using-dql/52215/2 "2025-06-24T16:44:28Z")

</div>

Hi&nbsp;[@walkadda](https://community.dynatrace.com/user/92472)&nbsp;,

you can try this probably this will work ?

```markup
fetch dt.entity.host
| fields entity.name, runs
| fieldsFlatten runs
| filter in(runs.dt.entity.service, $SERVICE)
| expand runs.dt.entity.service
| fields entity.name, runs.dt.entity.service
|fieldsAdd service_name = lookup([fetch dt.entity.service],
sourceField:runs.dt.entity.service, lookupField:id)[entity.name]

```

 ![Screenshot 2025-06-24 at 11.43.31 AM.png](https://global.discourse-cdn.com/dynatrace/original/2X/4/4ec109976f37b19b76021202bf35665853f949e2.png)

Br

---

<div class="post-metadata">

**Author:** ![TracingMySanity](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@TracingMySanity](https://community.dynatrace.com/u/TracingMySanity)\
**Post date:** [June 24, 2025, 5:22pm UTC](https://community.dynatrace.com/t/transposing-the-service-id-with-its-name-using-dql/52215/3 "2025-06-24T17:22:31Z")

</div>

If you’re filtering by service to look for the hosts it runs on, similar to&nbsp;[@Akhil-Jayendran](https://community.dynatrace.com/user/52584)’s solution, you can query the `runs_on` relationship on the service entity.

```markup
fetch dt.entity.service
| filter id == "SERVICE-FFB92DD67873FAC7"
| fieldsAdd runsOn = runs_on[dt.entity.host]
| filter isNotNull(runsOn)
| expand runsOn
| fields serviceName = entity.name, hostName = entityName(runsOn, type:"dt.entity.host")

```

 ![TracingMySanity_1-1750785658999.png](https://global.discourse-cdn.com/dynatrace/original/2X/1/1c8c29f9be647ba503b80b0c8e4701ce42f06638.png)
