I\'m trying to allow for passing in a field name and running it in an Ecto query expression dynamically, like so:
def count_distinct(query, field_name) when
You need to use field/2 to dynamically generate fields in queries:
query |> select([x], count(field(x, ^field_name), :distinct))
An example using the other query syntax for completion:
from x in query, select: count(field(x, ^field_name), :distinct)