# DQL - Count records bigger than in a array of records

**URL:** <https://community.dynatrace.com/t/dql-count-records-bigger-than-in-a-array-of-records/52702>\
**Category:** DQL\
**Tags:** dql\
**Created:** [July 29, 2025, 4:43pm UTC](https://community.dynatrace.com/t/dql-count-records-bigger-than-in-a-array-of-records/52702 "2025-07-29T16:43:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![m\_zol](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@m\_zol](https://community.dynatrace.com/u/m_zol)\
**Post date:** [July 29, 2025, 4:43pm UTC](https://community.dynatrace.com/t/dql-count-records-bigger-than-in-a-array-of-records/52702/1 "2025-07-29T16:43:16Z")

</div>

Hello,

Is there any way to count records in a array if the values are bigger than a number?

The scenario is to get the records from a response time timeseries metric and check how many records are more than 1.5 seconds and return the count.

The function **CountIf** doesn’t seems to work with arrays.

Anyone see a workaround?

Thanks

---

<div class="post-metadata">

**Author:** ![m\_zol](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@m\_zol](https://community.dynatrace.com/u/m_zol)\
**Post date:** [July 30, 2025, 12:34am UTC](https://community.dynatrace.com/t/dql-count-records-bigger-than-in-a-array-of-records/52702/2 "2025-07-30T00:34:17Z")

</div>

Hi,

I was able to, partially, get what I need using **expand** command.

```javascript
// Total de requests Válidas Com Sucesso
timeseries { Total_Requests_Sucesso = sum(dt.service.request.count), start=start(), end=end()}, by: { endpoint.name }, interval: 1m,
filter: { matchesValue(entityAttr(dt.entity.service, "tags"), $Tags) AND
       ((http.response.status_code >= 200 AND http.response.status_code <= 299) OR http.response.status_code == 422)}

// Total de requests Válidas Com Erro
| join [timeseries {Total_Requests_Erros = sum(dt.service.request.count, default:0), start=start(), end=end()}, by: {endpoint.name}, interval: 1m,
filter: {matchesValue(entityAttr(dt.entity.service, "tags"), $Tags) AND
       ((http.response.status_code >= 500 AND http.response.status_code <= 599) OR http.response.status_code == 408)}
], on: {endpoint.name}, fields:{Total_Requests_Erros, endpoint.name}

| filter matchesPhrase(endpoint.name, "POST /open-banking/payments/v4/pix/payments")

//Cálculo da Disponibilidade Pontual
| fieldsAdd Disponibilidade_Pontual = Total_Requests_Sucesso[] / (Total_Requests_Erros[] + Total_Requests_Sucesso[]) * 100

// Quantidade de registros no array (Disponível + Indisponível)
| fieldsAdd QuantidadeRegistros = arraySize(arrayRemoveNulls(Disponibilidade_Pontual))

// remoção de campos não necessários
//| FieldsRemove Total_Requests_Sucesso, Total_Requests_Erros

// expando os valores em diferentes linhas
| expand Disponibilidade_Pontual
| filter Disponibilidade_Pontual < 95

| summarize {
    Total_Indisponivel = count(),
    Total_Registros = takeLast(QuantidadeRegistros)

}, by:{endpoint.name, timeframe, interval}

| fieldsAdd TotalDisponivel = Total_Registros - Total_Indisponivel
| fieldsAdd Disponibilidade_Diaria = toDouble(TotalDisponivel) / toDouble(Total_Registros) * 100

```

 ![m_zol_0-1753835625743.png](https://global.discourse-cdn.com/dynatrace/original/2X/f/fc4bdb861511c4a187328f78a338c0e335c66aa1.png)

But this DQL gets the right result for one day, now I need to break the data for each day.. not sure how yet.

---

<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:** [August 5, 2025, 8:11pm UTC](https://community.dynatrace.com/t/dql-count-records-bigger-than-in-a-array-of-records/52702/3 "2025-08-05T20:11:34Z")

</div>

To count array elements fulfilling specific conditions you can use this query as example:

```markup
timeseries rt=avg(dt.service.request.response_time)
| fieldsAdd v=arraySum(iCollectArray(if(rt[]>100000,1, else:0)))

```

with iterative expressions you can perform array transformation, by applying formula to every element. This way we produce array of 0s or 1s (or nulls when array element is null). As a alst step we just need to sum array elements to have counts.

Example timeseries looks like this

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

and when I apply threshold of 100ms, I get this count:

 ![krzysztof_hoja_1-1754424105996.png](https://global.discourse-cdn.com/dynatrace/original/3X/1/0/10cea62988a16daef35d250179a69679b303fec5.png)

If you have multi day timeseries and want to have result grouped by days, here how to achieve it:

```markup
timeseries rt=avg(dt.service.request.response_time), timestamp=start()
| fieldsAdd d=record(rt=rt[], timestamp=timestamp[])
| expand d
| summarize v=countIf(d[rt]>90000), by: {timestamp=d[timestamp]@d}

```

 ![krzysztof_hoja_2-1754424671983.png](https://global.discourse-cdn.com/dynatrace/original/3X/7/a/7a69f910b697e7211a394c8b9ced75dcaef1058e.png)
