cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Declaring an array within a query and adding elements to it as the query iterates

Javin_Singh
Visitor

I am trying to declare an array (of integers) within a query and add elements to it based on the result of an if condition, using one of the record columns in the query.

 

However I am unable to do this or find any official support documentation to do so. Could I please know if it is possible and/or have a solution if it is.

 

Thank you.

 

Javin

2 REPLIES 2

krzysztof_hoja
Dynatrace Champion
Dynatrace Champion

Id sound line a need for use of collectArray or collectDistinct aggregation functions. Please take a look at example below (collection even integers) and result :

data record(x=1),
  record(x=2),
  record(x=3),
  record(x=4),
  record(x=null)
| summarize {ax=arrayRemoveNulls(collectArray( if( x % 2==0, x )))}

 

krzysztof_hoja_0-1732553588034.png

 

It would be helpful if you could share your existing query.

Kris

 

Hi Kris,

Thank you, the collectArray() function was the bit I was missing.

Javin

Featured Posts