0
votes

The first query below produces the correct output; however, my dataset has many datetime columns in which I would like to calculate the quarter. I would like to produce the same output using a user-defined function. I have attempted to create the function however I am getting a 'General_BadRequest' error and cannot figure out why. Can someone help correct my function below?

Also, is there a function already built into Kusto that calculates quarters?

Working Query - Output is Correct

range Date from todatetime('2021-01-01') to todatetime('2021-12-31') step 7d
| extend CaseMethod=case(
getmonth(Date) between (7 .. 9), 1,
getmonth(Date) between (10 .. 12), 2,
getmonth(Date) between (1 .. 3), 3,
getmonth(Date) between (4 .. 6), 4, 0)

Query with Function - Results in 'General_BadRequest'

let QtrFunc = (x:datetime) {
toscalar(
datatable ( Qtr:long, Mo_Start:long, Mo_End:long )
[ 1, 7,  9,
  2, 10, 12,
  3, 1,  3,
  4, 4,  6  ]
| where getmonth(x) between (Mo_Start .. Mo_End)
| project Qtr ) } ;
range DateCol from todatetime('2021-01-01') to todatetime('2021-12-31') step 7d
| extend FunctionMethod=QtrFunc(DateCol)