Ecto.Query's filter for aggregates used with type

Hi, I have a query for payments that I need to filter before summing up the values. I only need the paid ones.

type(sum(payment.amount), payment.amount) |> filter(payment.status == "paid")

However I am getting syntax error, maybe it is because of type?

I am using money_with_currency datatype for amount. I need to cast its type first before summing it to get the sum correctly. Here’s the info about it.