Issue with basic calculation causing card to error out

I am trying to do what I normally would think of as a basic calculation in beast mode, but it is continuting to error out my card as soon as I add it to the table.   I want to devide my revenue per client by the number of distinct cutomers.  My table looks like this


Client            Customers           Retail             Avg Customer

Smith                  4                     100                          25


in Excel I would calculate this as Retail/Customers, and it works fine.


So far in beast mode i have successfully written the count distinct portion as

(COUNT(DISTINCT (CONCAT(`Patient`,'',`Patient Address`,'',`Patient City`,'',`Patient Phone`))))

I have validated that it is correctly counting my customers against my original data set, so that part is correct.


I then tried to use the count distinct in the calculation  of

`Retail`/ (COUNT(DISTINCT (CONCAT(`Patient`,'',`Patient Address`,'',`Patient City`,'',`Patient Phone`))))


The formula validates when in Beast mode, but when I actually attempt to use it I reveive this error

An issue has occurred during processing. We are unable to complete the request at this time.
 I don't have a lot of SQL experience so I'm sure the answer is in front of my face, but I can not for the life of me figure out what I'm doing wrong.  There will always be a value for customers, so it shouldn't be a Divide by Zero error causing this, and I'm on day two of trying to get it right.


Best Answer

  • Valiant
    Valiant 🔵
    Accepted Answer

    Give this a shot. I think I ran into this a while back and had to include a CASE WHEN just in case there was the opportunity for a divide by 0.


    COUNT(DISTINCT (CONCAT(`Patient`,'',`Patient Address`,'',`Patient City`,'',`Patient Phone`))) <> 0
    THEN COUNT(DISTINCT (CONCAT(`Patient`,'',`Patient Address`,'',`Patient City`,'',`Patient Phone`)))
    ELSE 1 END

    Best of luck,