24 Apr 2025 08:43 PM
I would like to create a variable to be used in a segment that lets me filter based on tags. The idea is the tag is [AWS]ID and the values are X, Y, Z, I want to be able to filter by X,Y,Z and get their related hosts. I attempted to use the solution in https://community.dynatrace.com/t5/DQL/Create-a-variable-with-the-values-of-a-specific-tag/m-p/21806... but it's repeating the [AWS]IDs so it looks like we have multiples of one ID rather than individual IDs.
My original DQL was:
fetch dt.entity.host
| fieldsAdd tags
| expand tags
| fields tags
And the solution from the above link that I tried was:
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) == "[AWS]ID"
| fields value
Solved! Go to Solution.
24 Apr 2025 08:50 PM
Adding the dedup command at the end of your query might help.
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) == "[AWS]ID"
| fields value
| dedup value
24 Apr 2025 08:59 PM
Thank you, that helped!