Using average formula for a calculated column having sum and count



I am trying to get an average of a calculation having a sum and a count used in it. something looks wrong considering it is looking at the avg and then sum, can someone help me with this? or suggest an alternative if possible?

((CASE when SUM(`ext_sls_a`)/

COUNT((CASE when `listing_status`='APPROVED' AND `inventory`=0 then 'Live OOS items'
when `listing_status`='APPROVED' AND `inventory`>0 then 'Live Purchasable items'
else 'Pending, Rejected, Suspended' end)) then 'Live' else 'Not Live'
end ))


  • MarkSnodgrass
    MarkSnodgrass Portland, Oregon 🟤

    It looks as though your issue lies in the first case statement not having a condition. What do you want your SUM / COUNT to equal to in order to use `Live` ? That part appears to be missing. 

    Just before "then `Live`" you should have a greater than, or less than or equal to and a number. Hope that makes sense.

  • jaeW_at_Onyx
    jaeW_at_Onyx Budapest / Portland, OR 🟤

    ... i don't think you understood my last response to your last question.


    you have the same problem.  


    you're applying AVERAGE to an aggregated row.  SUM and a COUNT both of which will contain one row each.

    so your result will be the same as the value with AVG() removed.