Division By Zero - Be Aware - Failed IFERROR, IFNULL, and GROUPBY
When you're performing calculations over 100s of millions or records sometimes you come across division by zeros in which you're hoping the software you're using would manage accordingly, I ran into a scenario in an ETL scenario where it lead to having more than a 10% revenue shortfall in my numbers.
Generally in Domo if there is no data or if there is an error it will return a NULL in the output variable; however, if it is a division by zero, several functions fail to work with the output.
Figure 1: Input and Output
- Ratio = Num / Denom
- Ratio IFERROR = IFERROR(Num / Denom, 0 )
- Ratio IFNULL = IFULL( Num/Denom , 0)
- Ratio Backfill IFERROR = IFERROR(IFERROR(Num / Denom, 0 ),0)
In Figure 1 you can see in row 4 that the Ratio of Num
and Denom
yielded a blank calculation, however, both the IFERROR and IFNULL failed to backfill with the assigned zero.
Compared to Row 6 where the Ratio is also blank, but the IFNULL was able to backfill with zero. Not that a blank / blank for Domo is not necessarily an error, hence it did not meet the criteria for Ratio IF ERROR result of 0.
The real problem came when it was time to Group BY.
Figure 2: GroupBY Node
When I grouped by Products and sum Ratio
and Ratio IFERROR
, Product Y failed to sum in Figure 2 Row 3 because of the blank in row 4 (Division by Zero) from Figure 1, as opposed to Product Z which also had a blank cell in row 6, but was able to sum as seen in row 1 in Figure 2.
As a workaround, I used a case statement to check the denominator before computing the ratio.
case
when Denom = 0 then 0
else Num / Denom
end
Domo is aware of the issue, but be aware that IFERROR, IFNULL, and GROUP BY fails at managing division by zero errors.
Think about it this way, if Product Y was 1 million records and just 1 of those 1 million records had a division by zero, the sum of all 1 million records would result with a BLANK.
Comments
-
My hero!! Thank you!!
0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 616 Datasets
- 2.2K Magic ETL
- 3.8K Visualize
- 2.5K Charting
- 731 Beast Mode
- 55 App Studio
- 40 Variables
- 682 Automate
- 175 Apps
- 451 APIs & Domo Developer
- 46 Workflows
- 10 DomoAI
- 35 Predict
- 14 Jupyter Workspaces
- 21 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 122 Manage
- 119 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 107 Community Announcements
- 4.8K Archive