What kinds are there?
It’s not actually an aggregate, but a calculation that does the aggregate. But the error is quite clear that aggregates aren’t supported with ash_sqlite (it works with ash_postgres):
** (exit) an exception was raised:
** (Ash.Error.Invalid)
Bread Crumbs:
> Building expression for calculation: time_played_during([earliest_date: ~N[2025-12-10 00:00:00], latest_date: nil])
> Error returned from: DB.Music.Track.read_with_meta
Invalid Error
* Data layer for DB.Music.Track does not support using aggregates
(ash 3.11.3) lib/ash/error/query/aggregates_not_supported.ex:8: Ash.Error.Query.AggregatesNotSupported.exception/1
The calculation is a bit involved, I have this on tracks and web_tracks:
calculate :time_played_during,
:float,
expr(
duration *
sum(play_stats,
field: :completion_ratio,
query: [
filter:
expr(
(is_nil(^arg(:earliest_date)) or inserted_at >= ^arg(:earliest_date)) and
(is_nil(^arg(:latest_date)) or inserted_at <= ^arg(:latest_date))
)
]
)
) do
argument :earliest_date, :naive_datetime
argument :latest_date, :naive_datetime
end
And on another resource that uses this calculation on it’s relationships:
calculate :time_played_during,
:float,
expr(
(sum(tracks,
field: :time_played_during,
arguments: %{
earliest_date: ^arg(:earliest_date),
latest_date: ^arg(:latest_date)
}
) || 0) +
(sum(web_tracks,
field: :time_played_during,
arguments: %{
earliest_date: ^arg(:earliest_date),
latest_date: ^arg(:latest_date)
}
) || 0)
) do
argument :earliest_date, :naive_datetime
argument :latest_date, :naive_datetime
end
(Aside, I’m still a beginner ash user, if there is a better way to write that please let me know)






















