AIQL Application Insights query how to exclude weekends

1.2k views Asked by At

In some of my reports I'd like to exclude events that happen on weekends as our app is a business application that isn't running on the weekends, yet we do code updates and resulting tests on the weekends that can skew the data.

I've Tried:

and toint(dayofweek(timestamp)) >= 1 and toint(dayofweek(timestamp)) >= 5 //between Monday and Friday

But dayofweek returns a timespan, not an int, and the toint conversion doesn't work (no error is thrown, but result is an empty column.

So how do you exclude weekends? Can you convert timespan to int another way? Or is there another way to skin this cat?

2

There are 2 answers

1
EranG On BEST ANSWER

The following seems to work for me:

| parse tostring(dayofweek(timestamp)) with dayOfWeek:int ".00:00:00"

Following this line, dayOfWeek is an integer holding the day. From there you can slice and dice as needed.

Another option would be to use substring - might be faster the parse:

| project dayOfWeek = toint(substring(tostring(dayofweek(timestamp)), 0, 1))
0
Ziv Caspi On

Dividing one timestamp by another gives you back their ratio. So, if you divide dayofweek(timestamp) by 1d you'd get the result you need.