# DQL: How can I convert row values to column headings

**URL:** <https://community.dynatrace.com/t/dql-how-can-i-convert-row-values-to-column-headings/47445>\
**Category:** DQL\
**Tags:** dql\
**Created:** [September 3, 2024, 9:51am UTC](https://community.dynatrace.com/t/dql-how-can-i-convert-row-values-to-column-headings/47445 "2024-09-03T09:51:16Z")\
**Posts on this page:** 3\
**Page:** 1

<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:51am UTC](https://community.dynatrace.com/t/dql-how-can-i-convert-row-values-to-column-headings/47445/1 "2024-09-03T09:51:16Z")

</div>

I have some DQL that looks at a web servers log files and counts the number of hits on services gives me data in a table like this:

| service\_name | status\_code | hit\_count |
| --- | --- | --- |
| checkOut | 200 | 1234 |
| checkOut | 404 | 1 |

I would prefer to present it like this so that I can apply percentage calculations and categorise the record as being OK or needing action.

| service\_name | 200 | 404 |
| --- | --- | --- |
| checkOut | 1234 | 1 |

Is there a way to do this kind of thing?

---

<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 4, 2024, 12:52pm UTC](https://community.dynatrace.com/t/dql-how-can-i-convert-row-values-to-column-headings/47445/2 "2024-09-04T12:52:16Z")

</div>

Unfortunately the only technique I know to get it is via same method you probably saw already:  
[https://community.dynatrace.com/t5/DQL/DQL-How-to-Flatten-an-Array/m-p/251125/highlight/true#M1073](https://community.dynatrace.com/post/251125)

For your data it would look like:

```markup
data 
  record(serviceName="checkOut", status_code=200, hit_count=1234),
  record(serviceName="checkOut", status_code=404, hit_count=1),
  record(serviceName="login", status_code=200, hit_count=4),
  record(serviceName="login", status_code=403, hit_count=1)
| summarize { d=collectArray(array(toString(status_code),hit_count)) }, by: {serviceName}
| fieldsAdd d=toString(d)
| parse d, "'[' KVP{ '[' DQS:key ', ' LONG:value ']' ', '?}:code ']'"
| fieldsFlatten code
| fieldsRemove d, code

```

 ![krzysztof_hoja_0-1725454213375.png](https://global.discourse-cdn.com/dynatrace/original/2X/a/a18abb2f6cddea3c62f52afb1ea55fea7e2fad4e.png)

Kris

---

<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 4, 2024, 3:10pm UTC](https://community.dynatrace.com/t/dql-how-can-i-convert-row-values-to-column-headings/47445/3 "2024-09-04T15:10:54Z")

</div>

Thanks Kris, you are right I did read the other thread.&nbsp; &nbsp;This approach does work fine and is actually quite similar to how I would have approached in in SPL which is where my skillset is coming from.
