scflode
scflode
AEAsh Elixir
Created by scflode on 1/26/2023 in #support
Conditions in expr (calculations)
I have a calculation (taken from the getting started guide):
calculations do
calculate :percent_open, :float, expr(open_tickets / total_tickets)
end
calculations do
calculate :percent_open, :float, expr(open_tickets / total_tickets)
end
The issue here is (it's the representative assigned to a ticket) that this will error if a representative has no tickets. I tried to solve this with the if function to no avail.
calculations do
calculate :percent_open, :float, expr(if(total_tickets > 0, open_tickets / total_tickets, 100.0))
end
calculations do
calculate :percent_open, :float, expr(if(total_tickets > 0, open_tickets / total_tickets, 100.0))
end
This returns 100.0 for the total_tickets == 0 case but 0.0 for the rest. The resulting query also looks a bit weird (to me at least). It might be a problem that open_tickets and total_tickets themselves are aggregates.
aggregates do
count :total_tickets, :tickets

count :open_tickets, :tickets do
filter expr(status == :open)
end
end
aggregates do
count :total_tickets, :tickets

count :open_tickets, :tickets do
filter expr(status == :open)
end
end
Has anyone an idea?
33 replies