Beast mode to kill div0 errors
Hi, can anyone tell me why If my "A" code works, and my "B" CASE WHEN... THEN 0 ELSE 2 END code works, why can't I substitute code "A" for "2" in code B? I'm trying to kill divide by zero errors in a beast mode.
A
SUM(IFNULL(`qty sold instock`,0))/SUM(IFNULL(`qty found`,0))
B
(CASE WHEN (IFNULL(`qty found`,0)) = 0 THEN 0 ELSE 2 END)
B ELSE A
(CASE WHEN (IFNULL(`qty found`,0)) = 0 THEN 0 ELSE (SUM(IFNULL(`qty sold instock`,0))/SUM(IFNULL(`qty found`,0))) END)
Thanks
Best Answers

You might need to provide some sample rows of your data. I took your final beast mode:
(CASE WHEN (IFNULL(`qty found`,0)) = 0 THEN 0 ELSE (SUM(IFNULL(`qty sold instock`,0))/SUM(IFNULL(`qty found`,0))) END)
And put together some sample rows with the same columns that look like this and beast mode calc worked.
**Check out my Domo Tips & Tricks Videos
**Make sure to any users posts that helped you.
**Please mark as accepted the ones who solved your issue.0 
I thought it should work! There must be some NULL or ZERO scenario I failed to address. This code considering all NULL and ZERO possibilities does work.
CASE
WHEN (SUM(IFNULL(`qty sold instock`,0)) + SUM(IFNULL(`qty found`,0))) = 0 THEN 0
WHEN (SUM(IFNULL(`qty found`,0))) = 0 THEN 0
WHEN (SUM(IFNULL(`qty sold instock`,0))) = 0 THEN 0
ELSE (SUM(`qty sold instock`)*1) / SUM(`qty found`)
END
Thanks!
0
Answers

I found another way to accomplish this with more WHEN statements. Just curious why the B ELSE A does not work.
0 
You might need to provide some sample rows of your data. I took your final beast mode:
(CASE WHEN (IFNULL(`qty found`,0)) = 0 THEN 0 ELSE (SUM(IFNULL(`qty sold instock`,0))/SUM(IFNULL(`qty found`,0))) END)
And put together some sample rows with the same columns that look like this and beast mode calc worked.
**Check out my Domo Tips & Tricks Videos
**Make sure to any users posts that helped you.
**Please mark as accepted the ones who solved your issue.0 
I thought it should work! There must be some NULL or ZERO scenario I failed to address. This code considering all NULL and ZERO possibilities does work.
CASE
WHEN (SUM(IFNULL(`qty sold instock`,0)) + SUM(IFNULL(`qty found`,0))) = 0 THEN 0
WHEN (SUM(IFNULL(`qty found`,0))) = 0 THEN 0
WHEN (SUM(IFNULL(`qty sold instock`,0))) = 0 THEN 0
ELSE (SUM(`qty sold instock`)*1) / SUM(`qty found`)
END
Thanks!
0
Categories
 All Categories
 1.1K Product Ideas
 1.1K Ideas Exchange
 1.2K Connect
 969 Connectors
 256 Workbench
 Cloud Amplifier
 1 Federated
 2.4K Transform
 76 SQL DataFlows
 500 Datasets
 1.8K Magic ETL
 2.7K Visualize
 2.2K Charting
 373 Beast Mode
 20 Variables
 484 Automate
 102 Apps
 378 APIs & Domo Developer
 6 Workflows
 22 Predict
 6 Jupyter Workspaces
 16 R & Python Tiles
 316 Distribute
 64 Domo Everywhere
 252 Scheduled Reports
 59 Manage
 59 Governance & Security
 1 Product Release Questions
 5K Community Forums
 37 Getting Started
 23 Community Member Introductions
 63 Community Announcements
 4.8K Archive