Hey @Purohit, Aahana !
It seems this TSX in your aggregation clause - "max($event.$ts) - min($event.$ts)" - may be the issue. Subtracting timestamps would give you a Timespan data type which is not currently supported. See the supported data types here.
Additionally, to answer your question in the above comments about interval calculations, here's an example:
The green shows the query's search span, the orange shows interval size and the blue shows the intervals that TSI generates starting at Unix epoch. Now it may happen that the calculated intervals don't align with the search span chosen. In this case, we'd take the interval in which your search span begins as the first bucket and will take the interval in which your search span ends as the last bucket and perform the aggregations.
Each interval considers data including the left boundary up until the right boundary. The timestamps that are returned by the query are of the left interval boundary. In this example, T1, the first timestamp returned, occurs before the "from" time on the search span. This may look strange, but we do not consider any events that fall outside of the search span. So the first two points and the last two will not be included in the aggregation for T1 and T5, respectively. If we don’t find data, like for the interval T3 and T4, we return null for that interval. From this image, the query would return 5 timestamps and 3 values (value, value, null, null, value).
So, if we take your example in the comments above, we see no data for "2021-01-05T13:41:25Z" and value X at "2021-01-05T13:41:26Z". The interval starting at "2021-01-05T13:41:24Z" would return null (similar to interval T4 in the example). The next interval starting at "2021-01-05T13:41:26Z" would include the value X in it's aggregation.
I hope that helps, please let me know if you have more questions!!