kusto 查询 - 我想在图表上排除第 2 个和第 4 个星期六以及星期日
kusto query - i want exclude 2nd and 4th Saturday along with Sunday on chart
我想排除图表上的第 2 个和第 4 个星期六以及星期日。
我正在尝试这段代码,但它不起作用,它给出了一个错误 -
Relop semantic error: SEM0025: One of the values provided to the 'in'
operator does not match the left side expression type 'timespan',
consider using explicit cast
| extend Eventdate = strcat(datetime_part("day",timestamp))
| extend day = dayofweek(timestamp)
| extend day_strg = tostring(Eventdate)
| extend Week_Num = case(
day_strg in (range(1, 7, 1)), "1",
day_strg in (range(8, 14, 1)), "2",
day_strg in (range(15, 21, 1)), "3",
day_strg in (range(22, 31, 1)), "4",
"0")
| extend weekend = case(Week_Num in (2, 4) and day in (5, 6), "weekend","working day")
| project Eventdate, timestamp, day, day_strg, Week_Num, weekend
这是您所要求的示例:
range timestamp from datetime(2022-02-01 08:06:45.7316316) to datetime(2022-03-01 08:06:45.7316316) step 1d
| extend DayOfMonth = dayofmonth(timestamp)
| extend Day = startofday(timestamp)
| extend Week_Num = case(
DayOfMonth <=7, 1,
DayOfMonth <=14, 2,
DayOfMonth <=21, 3,
DayOfMonth <=28, 4,
5)
| extend weekend = iif((Week_Num in (2, 4) and (dayofweek(timestamp)/1d) == 6) or dayofweek(timestamp)/1d == 0, "weekend","working day")
| project timestamp, Day, Week_Num, weekend
timestamp
Day
Week_Num
weekend
2022-02-01 08:06:45.7316316
2022-02-01 00:00:00.0000000
1
working day
2022-02-02 08:06:45.7316316
2022-02-02 00:00:00.0000000
1
working day
2022-02-03 08:06:45.7316316
2022-02-03 00:00:00.0000000
1
working day
2022-02-04 08:06:45.7316316
2022-02-04 00:00:00.0000000
1
working day
2022-02-05 08:06:45.7316316
2022-02-05 00:00:00.0000000
1
working day
2022-02-06 08:06:45.7316316
2022-02-06 00:00:00.0000000
1
weekend
2022-02-07 08:06:45.7316316
2022-02-07 00:00:00.0000000
1
working day
2022-02-08 08:06:45.7316316
2022-02-08 00:00:00.0000000
2
working day
2022-02-09 08:06:45.7316316
2022-02-09 00:00:00.0000000
2
working day
2022-02-10 08:06:45.7316316
2022-02-10 00:00:00.0000000
2
working day
2022-02-11 08:06:45.7316316
2022-02-11 00:00:00.0000000
2
working day
2022-02-12 08:06:45.7316316
2022-02-12 00:00:00.0000000
2
weekend
2022-02-13 08:06:45.7316316
2022-02-13 00:00:00.0000000
2
weekend
2022-02-14 08:06:45.7316316
2022-02-14 00:00:00.0000000
2
working day
2022-02-15 08:06:45.7316316
2022-02-15 00:00:00.0000000
3
working day
2022-02-16 08:06:45.7316316
2022-02-16 00:00:00.0000000
3
working day
2022-02-17 08:06:45.7316316
2022-02-17 00:00:00.0000000
3
working day
2022-02-18 08:06:45.7316316
2022-02-18 00:00:00.0000000
3
working day
2022-02-19 08:06:45.7316316
2022-02-19 00:00:00.0000000
3
working day
2022-02-20 08:06:45.7316316
2022-02-20 00:00:00.0000000
3
weekend
2022-02-21 08:06:45.7316316
2022-02-21 00:00:00.0000000
3
working day
2022-02-22 08:06:45.7316316
2022-02-22 00:00:00.0000000
4
working day
2022-02-23 08:06:45.7316316
2022-02-23 00:00:00.0000000
4
working day
2022-02-24 08:06:45.7316316
2022-02-24 00:00:00.0000000
4
working day
2022-02-25 08:06:45.7316316
2022-02-25 00:00:00.0000000
4
working day
2022-02-26 08:06:45.7316316
2022-02-26 00:00:00.0000000
4
weekend
2022-02-27 08:06:45.7316316
2022-02-27 00:00:00.0000000
4
weekend
2022-02-28 08:06:45.7316316
2022-02-28 00:00:00.0000000
4
working day
2022-03-01 08:06:45.7316316
2022-03-01 00:00:00.0000000
1
working day
我想排除图表上的第 2 个和第 4 个星期六以及星期日。
我正在尝试这段代码,但它不起作用,它给出了一个错误 -
Relop semantic error: SEM0025: One of the values provided to the 'in' operator does not match the left side expression type 'timespan', consider using explicit cast
| extend Eventdate = strcat(datetime_part("day",timestamp))
| extend day = dayofweek(timestamp)
| extend day_strg = tostring(Eventdate)
| extend Week_Num = case(
day_strg in (range(1, 7, 1)), "1",
day_strg in (range(8, 14, 1)), "2",
day_strg in (range(15, 21, 1)), "3",
day_strg in (range(22, 31, 1)), "4",
"0")
| extend weekend = case(Week_Num in (2, 4) and day in (5, 6), "weekend","working day")
| project Eventdate, timestamp, day, day_strg, Week_Num, weekend
这是您所要求的示例:
range timestamp from datetime(2022-02-01 08:06:45.7316316) to datetime(2022-03-01 08:06:45.7316316) step 1d
| extend DayOfMonth = dayofmonth(timestamp)
| extend Day = startofday(timestamp)
| extend Week_Num = case(
DayOfMonth <=7, 1,
DayOfMonth <=14, 2,
DayOfMonth <=21, 3,
DayOfMonth <=28, 4,
5)
| extend weekend = iif((Week_Num in (2, 4) and (dayofweek(timestamp)/1d) == 6) or dayofweek(timestamp)/1d == 0, "weekend","working day")
| project timestamp, Day, Week_Num, weekend
timestamp | Day | Week_Num | weekend |
---|---|---|---|
2022-02-01 08:06:45.7316316 | 2022-02-01 00:00:00.0000000 | 1 | working day |
2022-02-02 08:06:45.7316316 | 2022-02-02 00:00:00.0000000 | 1 | working day |
2022-02-03 08:06:45.7316316 | 2022-02-03 00:00:00.0000000 | 1 | working day |
2022-02-04 08:06:45.7316316 | 2022-02-04 00:00:00.0000000 | 1 | working day |
2022-02-05 08:06:45.7316316 | 2022-02-05 00:00:00.0000000 | 1 | working day |
2022-02-06 08:06:45.7316316 | 2022-02-06 00:00:00.0000000 | 1 | weekend |
2022-02-07 08:06:45.7316316 | 2022-02-07 00:00:00.0000000 | 1 | working day |
2022-02-08 08:06:45.7316316 | 2022-02-08 00:00:00.0000000 | 2 | working day |
2022-02-09 08:06:45.7316316 | 2022-02-09 00:00:00.0000000 | 2 | working day |
2022-02-10 08:06:45.7316316 | 2022-02-10 00:00:00.0000000 | 2 | working day |
2022-02-11 08:06:45.7316316 | 2022-02-11 00:00:00.0000000 | 2 | working day |
2022-02-12 08:06:45.7316316 | 2022-02-12 00:00:00.0000000 | 2 | weekend |
2022-02-13 08:06:45.7316316 | 2022-02-13 00:00:00.0000000 | 2 | weekend |
2022-02-14 08:06:45.7316316 | 2022-02-14 00:00:00.0000000 | 2 | working day |
2022-02-15 08:06:45.7316316 | 2022-02-15 00:00:00.0000000 | 3 | working day |
2022-02-16 08:06:45.7316316 | 2022-02-16 00:00:00.0000000 | 3 | working day |
2022-02-17 08:06:45.7316316 | 2022-02-17 00:00:00.0000000 | 3 | working day |
2022-02-18 08:06:45.7316316 | 2022-02-18 00:00:00.0000000 | 3 | working day |
2022-02-19 08:06:45.7316316 | 2022-02-19 00:00:00.0000000 | 3 | working day |
2022-02-20 08:06:45.7316316 | 2022-02-20 00:00:00.0000000 | 3 | weekend |
2022-02-21 08:06:45.7316316 | 2022-02-21 00:00:00.0000000 | 3 | working day |
2022-02-22 08:06:45.7316316 | 2022-02-22 00:00:00.0000000 | 4 | working day |
2022-02-23 08:06:45.7316316 | 2022-02-23 00:00:00.0000000 | 4 | working day |
2022-02-24 08:06:45.7316316 | 2022-02-24 00:00:00.0000000 | 4 | working day |
2022-02-25 08:06:45.7316316 | 2022-02-25 00:00:00.0000000 | 4 | working day |
2022-02-26 08:06:45.7316316 | 2022-02-26 00:00:00.0000000 | 4 | weekend |
2022-02-27 08:06:45.7316316 | 2022-02-27 00:00:00.0000000 | 4 | weekend |
2022-02-28 08:06:45.7316316 | 2022-02-28 00:00:00.0000000 | 4 | working day |
2022-03-01 08:06:45.7316316 | 2022-03-01 00:00:00.0000000 | 1 | working day |