# Add getDayOfYear array as a filter in "if else" check - help with syntax

**URL:** <https://community.dynatrace.com/t/add-getdayofyear-array-as-a-filter-in-if-else-check-help-with-syntax/47375>\
**Category:** DQL\
**Tags:** dql\
**Created:** [August 29, 2024, 7:40am UTC](https://community.dynatrace.com/t/add-getdayofyear-array-as-a-filter-in-if-else-check-help-with-syntax/47375 "2024-08-29T07:40:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlanFoley](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@AlanFoley](https://community.dynatrace.com/u/AlanFoley)\
**Post date:** [August 29, 2024, 7:40am UTC](https://community.dynatrace.com/t/add-getdayofyear-array-as-a-filter-in-if-else-check-help-with-syntax/47375/1 "2024-08-29T07:40:34Z")

</div>

Hi All

I am working worth a service metric - in this case Response Time - where I want to split by Business Hours (BH) and Non Business Hours (NBH) - this works fine as I also include Sat and Sat into NBH

The next step I want to do is include a list of public holidays to be included in NBH by providing an “Array” containing a list of these days as per “getDayOfYear” format to match against

In the code below my attempt at this is commented out

I need some help with the correct syntax - am I on the right track?

Apprecaite the help

 ![DQL1.png](https://global.discourse-cdn.com/dynatrace/original/3X/e/6/e6ef919e259855fc4a88695831a30a22b90a1c2b.png)

### DQL ###

timeseries {AvgResponseTime=avg(dt.service.request.response\_time,default:0),e=end()},interval:1h,by:{dt.entity.service}  
// ,from:“2024-04-01T00:00:00” ,to:“2024-04-30T23:59:59” // Select the month  
| filter dt.entity.service == “SERVICE-xxx”  
| fieldsAdd AvgResponseTime\_BH = if( getHour(e[])\>6 and getHour(e[])\<19 and getDayOfWeek(e[]) \<6, AvgResponseTime[])  
,AvgResponseTime\_NBH = if( getHour(e[])\<7 or getHour(e[])\>18, AvgResponseTime[]  
,else:if(getDayOfWeek(e[]) \>5, AvgResponseTime[] //Include Sat and Sun  
// Need to Include Public Holiday’s to Non Business Hours [all 24 hours]  
// ,else:if(getDayOfYear(e[]) in(e[],array,(“1”,“81”,“89”,“92”,“118”,“122”,“168”,“222”,“268”,“351”,“360”,“361”)), AvgResponseTime[]  
))  
// Temp fields to verify Monthly Hour totals for Business Hours and Non Business Hours  
| fieldsAdd HoursInMonth = arraySize(arrayRemoveNulls(AvgResponseTime))  
,Hours\_BH = arraySize(arrayRemoveNulls(AvgResponseTime\_BH))  
,Hours\_NBH = arraySize(arrayRemoveNulls(AvgResponseTime\_NBH))  
| fieldsAdd Hours\_Check\_MustBeZero = HoursInMonth - (Hours\_BH + Hours\_NBH)  
| fieldsRemove AvgResponseTime,AvgResponseTime\_BH,AvgResponseTime\_NBH

---

<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 30, 2024, 9:12pm UTC](https://community.dynatrace.com/t/add-getdayofyear-array-as-a-filter-in-if-else-check-help-with-syntax/47375/2 "2024-08-30T21:12:46Z")

</div>

I would do it this way:

```markup
| fieldsAdd bh = getHour(e[])>6 and getHour(e[])<19 and getDayOfWeek(e[]) <6 and not in(getDayOfYear(e[]), array(1,81,89,92,118,122,168,222,268,351,360,361))
| fieldsAdd 
    AvgResponseTime_BH = if( bh[], AvgResponseTime[]),
    AvgResponseTime_NBH = if( not bh[], AvgResponseTime[] )
| fieldsAdd 
    HoursInMonth = arraySize(arrayRemoveNulls(AvgResponseTime)),
    Hours_BH = arraySize(arrayRemoveNulls(AvgResponseTime_BH)),
    Hours_NBH = arraySize(arrayRemoveNulls(AvgResponseTime_NBH))
| fieldsAdd Hours_Check_MustBeZero = HoursInMonth - (Hours_BH + Hours_NBH)
| fieldsRemove AvgResponseTime,AvgResponseTime_BH,AvgResponseTime_NBH, bh

```

---

<div class="post-metadata">

**Author:** ![AlanFoley](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@AlanFoley](https://community.dynatrace.com/u/AlanFoley)\
**Post date:** [September 3, 2024, 4:39am UTC](https://community.dynatrace.com/t/add-getdayofyear-array-as-a-filter-in-if-else-check-help-with-syntax/47375/3 "2024-09-03T04:39:23Z")

</div>

Hi krzysztof\_hoja

Works great

Appreciate your time

Thanks a mil

Alan

[Preview](https://community.dynatrace.com/topic/254470#)
