Scalar UDF are not existent yet in BigQuery
See more about BigQuery User-Defined Functions to understand what are they today. To simplify - think of today's UDF as virtual table that you can query and this table in turn powered by real table where each row is processed row-by-row and javascript code is applied for each row and generates (instead of this input row) zero, one or many (depends of inplemented in js logic) rows)Use below
CREATE FUNCTION east_or_west(long float64) as ((
SELECT COUNT(*)
FROM `project.dataset.MODELS` m
WHERE m.areaid = (
CASE
WHEN long > 0.00 THEN 10
WHEN long < 0.00 THEN 20
ELSE 5
END
)
));
You need reference UDF with dataset prefix, otherwise BigQuery think it is a builtin function or temporary UDF. In your case, just change to TO_CHAR. Assuming your mytable.TO_CHAR is actually a dataset.mytable
SELECT mytable.TO_CHAR(End_Time, 'yyyy-mm') AS Month_and_Year,