# Flatten Arrays in Dynatrace Query Language (DQL)

**URL:** <https://community.dynatrace.com/t/flatten-arrays-in-dynatrace-query-language-dql/46708>\
**Category:** DQL\
**Tags:** dql\
**Created:** [July 19, 2024, 1:23pm UTC](https://community.dynatrace.com/t/flatten-arrays-in-dynatrace-query-language-dql/46708 "2024-07-19T13:23:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![36Krazyfists](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/36krazyfists/32/37434_2.png) [@36Krazyfists](https://community.dynatrace.com/u/36Krazyfists)\
**Post date:** [July 19, 2024, 1:23pm UTC](https://community.dynatrace.com/t/flatten-arrays-in-dynatrace-query-language-dql/46708/1 "2024-07-19T13:23:21Z")

</div>

_Summary: This article demonstrates how to flatten arrays using DQL functions. It provides syntax examples and practical use cases for transforming complex data structures in Dynatrace dashboards._

So you can flatten records to individual columns using the fieldsFlatten command, but there’s no way to flatten arrays. You can expand arrays, but that creates separate rows for each element in an array. I want columns made for each element in the array.

Here’s the query I’m running:

```auto
fetch dt.entity.host
| fieldsAdd state, osVersion, managementZones
| filter state == "OFFLINE"
| sort entity.name

```

The managementZones column has arrays of management zones in it. I want to flatten that into columns of management zones (so mzone1, mzone2, mzone3, mzone4, etc…). Or, if it’s easier, the management zone names could become columns with something like TRUE/FALSE in the cell as well.

Anybody know if this is possible?

---

<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:** [July 19, 2024, 8:50pm UTC](https://community.dynatrace.com/t/flatten-arrays-in-dynatrace-query-language-dql/46708/2 "2024-07-19T20:50:27Z")

</div>

No, unfortunately it is not possible to do in clean DQL, however it is possible to workaround it using DPL and string representation of the array.

You may try this:

```markup
fetch dt.entity.host
| fieldsAdd managementZones=array(managementZones[],true)
| fieldsAdd managementZones= toString(managementZones)
| parse managementZones, "'[' KVP{ '[' DQS:key ', ' BOOLEAN:value ']' ', '?}:mz ']'"
| fieldsFlatten mz
| fieldsRemove managementZones, mz

```

The result looks for me like this:

 ![krzysztof_hoja_0-1721422124670.png](https://global.discourse-cdn.com/dynatrace/original/3X/2/4/248102229b405fb30b2e4ec75b2469513226f6a0.png)

true is value of the fields names as management zone. When host is not in management zone the filed is simply missing

Kris

---

<div class="post-metadata">

**Author:** ![36Krazyfists](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/36krazyfists/32/37434_2.png) [@36Krazyfists](https://community.dynatrace.com/u/36Krazyfists)\
**Post date:** [July 21, 2024, 7:29pm UTC](https://community.dynatrace.com/t/flatten-arrays-in-dynatrace-query-language-dql/46708/3 "2024-07-21T19:29:31Z")

</div>

Wow, you replied to one of my other DQL questions with a similarly advanced query.&nbsp; Not sure how you’ve learned all this advanced stuff given what’s available in the documentation that Dynatrace has provided…

Do you have some secret source of documentation, tips, and examples that the rest of us mere mortals don’t have access to, or did you figure all this stuff out on your own?

---

<div class="post-metadata">

**Author:** ![HeadScratcher](https://avatars.discourse-cdn.com/v4/letter/h/85f322/32.png) [@HeadScratcher](https://community.dynatrace.com/u/HeadScratcher)\
**Post date:** [September 3, 2024, 9:13am UTC](https://community.dynatrace.com/t/flatten-arrays-in-dynatrace-query-language-dql/46708/4 "2024-09-03T09:13:50Z")

</div>

[@36Krazyfists](https://community.dynatrace.com/user/41155)&nbsp; &nbsp;you have articulated very well what I am thinking…&nbsp; &nbsp; There need to be more examples in the docs.
