Averages with null values

Options
Using Function Stack, and querying all records, I get the list of all my data.

Now i'm trying to get averages over multiple fields.
Ex: Car_usage: 1 to 5 
Car_motor_usage: 1 to 5
...
So each record row is for 1 car but with multiple ratings.
The problem is that if someone doesn't know for example the "car_motor_usage": the equivelent of N/A or don't know would be a null value in the data so just empty.

But the function stack on aggregator has Average only which counts the empty value as a Zero.

What would be then an alternative to calculate the average excluding null value?

Thanks guys!

Comments

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options
    So this is a little tricky because you need the sum of ratings divided by the count to get a mean. But the counts are different for each metric. Fortunately you can handle this in the function stack- just increment a counter for each metric along with adding to the total when the value is not null. This will mean you need to keep track of each counter separately but that’s not the biggest deal in the world.

    There may be a way to one-line this in the database call using an aggregator too. Which solution is right for you will depend on the details of your use case.

    Let me know if you want to work this together! It sounds like maybe 30m would get you through it.