Chris Potts
10/27/2026, 3:34 PMselect (DATETIME_DIFF({label/delayed.day},{label/fulfilled.day} ))where {label/fulfilled.day} <> NULL and {label/delayed.day} != NULLkapa.ai
10/27/2026, 3:34 PMDATETIME_DIFF is not an aggregation function. You must either: âĸ Apply aggregation inside DATETIME_DIFF (on the date arguments), or âĸ Wrap DATETIME_DIFF in an aggregation function like SUM, AVG, etc., using the BY {dataset} keyword. Your formula has no aggregation at all, which is why you're getting the error. 2. NULL Filtering Syntax For NULL comparisons in MAQL, you should use <> (or !=) with NULL directly â both are valid per the docs. However, the correct approach for filtering out NULLs on date labels would be: SELECT {label/delayed.day} <> NULL SELECT {label/fulfilled.day} <> NULL Corrected Formula Assuming delayed and fulfilled are date dimensions referenced from a common dataset (e.g., orders), use the BY {dataset} pattern: SELECT AVG( SELECT DATETIME_DIFF({label/delayed.day}, {label/fulfilled.day}) BY {dataset/orders} WHERE {label/fulfilled.day} <> NULL AND {label/delayed.day} <> NULL ) Or, if you want the sum of differences: SELECT SUM( SELECT DATETIME_DIFF({label/delayed.day}, {label/fulfilled.day}) BY {dataset/orders} WHERE {label/fulfilled.day} <> NULL AND {label/delayed.day} <> NULL ) > Important: Replace {dataset/orders} with the actual identifier of the dataset that contains your date columns. You must specify the source dataset even if there is only one reference to the Date dataset in your model. [DATETIME_DIFF docs] The NULL filtering using <> NULL translates to IS NOT NULL in SQL, which is the correct semantic for excluding null date rows. [Relational Operators] đ 0 button đ 0 button âšī¸ Tip: Mention @kapa.ai in the thread for follow-ups. đ Our Support team monitors all messages and will jump in if needed.