# Create a variable with the values of a specific tag

**URL:** <https://community.dynatrace.com/t/create-a-variable-with-the-values-of-a-specific-tag/40702>\
**Category:** DQL\
**Tags:** dql, dashboards\
**Created:** [July 14, 2023, 10:59am UTC](https://community.dynatrace.com/t/create-a-variable-with-the-values-of-a-specific-tag/40702 "2023-07-14T10:59:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![elenaperez](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/elenaperez/32/38054_2.png) [@elenaperez](https://community.dynatrace.com/u/elenaperez)\
**Post date:** [July 14, 2023, 10:59am UTC](https://community.dynatrace.com/t/create-a-variable-with-the-values-of-a-specific-tag/40702/1 "2023-07-14T10:59:06Z")

</div>

I would like to create a variable that contains the values of a specific tag for the hosts. I’m trying to create the query to get these values.  
Basically if the tag is called Business Application and the values are X, Y, Z I would like to get X, Y and Z.I tried with this but it gives me all the tags for the different hosts:

```c-mrkdwn__pre
fetch dt.entity.host
| summarize count = count(), by:{tags}
| sort count desc
| fields tags

```

I guess you would need to parse the individual tags and separate them if they are key:value.  
How could I create this query?

---

<div class="post-metadata">

**Author:** ![sinisa\_zubic](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/sinisa_zubic/32/32498_2.png) [@sinisa\_zubic](https://community.dynatrace.com/u/sinisa_zubic)\
**Post date:** [July 14, 2023, 11:10am UTC](https://community.dynatrace.com/t/create-a-variable-with-the-values-of-a-specific-tag/40702/2 "2023-07-14T11:10:43Z")

</div>

Hi&nbsp;[@elenaperez](https://community.dynatrace.com/user/58054)

to get a list of unique tag values for the tag “Business Application” this dql query should work for you

```markup
fetch dt.entity.host
| expand tags
| summarize tags = collectDistinct(tags)
| expand tags
| parse tags, """((LD:tag (!<<'\\' ':') LD:value)|LD:tag)"""
| fields tag = replaceString(tag,"""\:""", ":"), value = replaceString(value, """\:""", ":")
| filter toString(tag) == "Business Application"
| fields value

```

Best,  
Sini

---

<div class="post-metadata">

**Author:** ![elenaperez](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/elenaperez/32/38054_2.png) [@elenaperez](https://community.dynatrace.com/u/elenaperez)\
**Post date:** [July 14, 2023, 11:25am UTC](https://community.dynatrace.com/t/create-a-variable-with-the-values-of-a-specific-tag/40702/3 "2023-07-14T11:25:43Z")

</div>

Thank you so much, it is exactly what I was looking for! Super helpful
