# Is there a way to get row\_number () or any function to generate sequential number in DQL ?

**URL:** <https://community.dynatrace.com/t/is-there-a-way-to-get-row-number-or-any-function-to-generate-sequential-number-in-dql/49620>\
**Category:** DQL\
**Tags:** dql, notebooks\
**Created:** [January 8, 2025, 5:23pm UTC](https://community.dynatrace.com/t/is-there-a-way-to-get-row-number-or-any-function-to-generate-sequential-number-in-dql/49620 "2025-01-08T17:23:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![susmita\_k](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@susmita\_k](https://community.dynatrace.com/u/susmita_k)\
**Post date:** [January 8, 2025, 5:23pm UTC](https://community.dynatrace.com/t/is-there-a-way-to-get-row-number-or-any-function-to-generate-sequential-number-in-dql/49620/1 "2025-01-08T17:23:15Z")

</div>

Is there a way to get row\_number () or any function to generate sequential number in DQL ?

---

<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:** [January 13, 2025, 1:12pm UTC](https://community.dynatrace.com/t/is-there-a-way-to-get-row-number-or-any-function-to-generate-sequential-number-in-dql/49620/2 "2025-01-13T13:12:22Z")

</div>

You can generate table with indexes if you have your data in form of timeseries using _iIndex()_ function in iterative expression.

Can you share your query end explain where/why you want to “number” you data?

Kris

---

<div class="post-metadata">

**Author:** ![susmita\_k](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@susmita\_k](https://community.dynatrace.com/u/susmita_k)\
**Post date:** [January 13, 2025, 1:42pm UTC](https://community.dynatrace.com/t/is-there-a-way-to-get-row-number-or-any-function-to-generate-sequential-number-in-dql/49620/3 "2025-01-13T13:42:44Z")

</div>

Thank you. Here is the DQL

fetch dt.entity.host  
| fieldsAdd managementZones  
| expand managementZones  
| filter managementZones == “mz\_prod”&nbsp;  
|expand tags  
  |parse tags, “”“((LD:tag (!\<\<‘\\’ ‘:’) LD:value)|LD:tag)”“”  
  |filter tag == “AppName”&nbsp;  
|fieldsAdd AppName = value  
|filter AppName == “App1”  
|fieldsAdd&nbsp; pm=ceil(toDouble(physicalMemory)/1000000000)  
|fields AppName, entity.name,&nbsp;&nbsp; pm  
|summarize d=collectArray(record(AppName, entity.name,&nbsp;&nbsp; pm))  
|fields a = record(value = d[], index = iIndex())  
|expand a  
|fields test =a[value], index = a[index]  
|fields AppName=test[AppName],entity.name=test[entity.name],pm=test[pm],index

I need the index (sequence #) to compare with hosts of another Management zone for the same appName.

Can you please suggest, how can I create a timeseries out of this result ? Thank you.

---

<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:** [January 13, 2025, 5:15pm UTC](https://community.dynatrace.com/t/is-there-a-way-to-get-row-number-or-any-function-to-generate-sequential-number-in-dql/49620/4 "2025-01-13T17:15:00Z")

</div>

I used word “timeseries”, while I should use just “array”.&nbsp;I see that you successfully used iIndex() function to get entity numbering.

I rewrote the query, so it can work on my test environment (adjusted filters) and did some simplification/compressions of syntax (use of _ **expand** _ can be avoided )

```markup
fetch dt.entity.host
| filter iAny(managementZones[]=="HipsterShopLogs")

| fieldsAdd ptags = parse(tags[], """('[' LD:context ']')?((LD:tag (!<<'\\' ':') LD:value)|LD:tag)""")
| fieldsAdd ptags = record(context=ptags[][context], tag=replaceString(ptags[][tag],"\\:",":"), 
  value=replaceString(ptags[][value],"\\:",":"), orig=tags[] )

| filter iAny(ptags[][tag]=="dt.cost.costcenter" and ptags[][value]=="business-intelligence/BI") 

| fieldsAdd pm=ceil(toDouble(physicalMemory)/1000000000)
| summarize d=collectArray(record(AppName=arrayFirst(iCollectArray(if(ptags[][tag]=="dt.cost.costcenter",ptags[])))[value] , entity.name, pm))
| fields a = record(value = d[], index = iIndex())
| expand a
| fields index = a[index], AppName=a[value][AppName],entity.name=a[value][entity.name], pm=a[value][pm]

```

and my result of a query looks like this:

 ![krzysztof_hoja_0-1736788342653.png](https://global.discourse-cdn.com/dynatrace/original/3X/0/b/0b4a52985098dcce316356fd972d554c11c5154e.png)

If you have similar query for a different MZ comparing result sets is possible of, but what is the desired criteria of comparison? And what is the role of the index in it?

---

<div class="post-metadata">

**Author:** ![susmita\_k](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@susmita\_k](https://community.dynatrace.com/u/susmita_k)\
**Post date:** [January 13, 2025, 5:45pm UTC](https://community.dynatrace.com/t/is-there-a-way-to-get-row-number-or-any-function-to-generate-sequential-number-in-dql/49620/5 "2025-01-13T17:45:26Z")

</div>

I am able to compare the memories of each hosts from different mz ( same app running in model and prod and we would like to compare the memory/cpu configuration in both the environment). I am looking to create a timeseries so I can configure the alert in davis AI anomaly detector and the concerned team will be notified when there is a mismatch found.
