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.8K Product Ideas
 1.8K Ideas Exchange
 1.5K Connect
 1.2K Connectors
 296 Workbench
 6 Cloud Amplifier
 8 Federated
 2.9K Transform
 100 SQL DataFlows
 614 Datasets
 2.2K Magic ETL
 3.8K Visualize
 2.5K Charting
 729 Beast Mode
 53 App Studio
 40 Variables
 677 Automate
 173 Apps
 451 APIs & Domo Developer
 45 Workflows
 8 DomoAI
 34 Predict
 14 Jupyter Workspaces
 20 R & Python Tiles
 394 Distribute
 113 Domo Everywhere
 275 Scheduled Reports
 6 Software Integrations
 121 Manage
 118 Governance & Security
 Domo Community Gallery
 32 Product Releases
 10 Domo University
 5.4K Community Forums
 40 Getting Started
 30 Community Member Introductions
 108 Community Announcements
 4.8K Archive