turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Dojo
- :
- Using Domo
- :
- Beast Mode, ETL/Dataflow
- :
- Re: Beast Mode Help: Two layers of division

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-09-2017
07:22 AM

10-09-2017
07:22 AM

I've got a calculation I am trying to perform with a beast mode formula, that I can't get to work.

The calculation is **(Number of Lines / Hours Active) / Standard **

I'm trying to protect against divide by zero in the two layers of the formula. The first item in the order of operation is the **(Number of Lines / Hours Active)**, then the result of that calculation is **/ Standard **

Here is the beast mode I attempted, but is not working. I know this case is checking for NULL, do I need to check for zero as well?

CASE

WHEN IFNULL(SUM(`RCV Standard - Dynamic`),0)=0

THEN 0

ELSE

(CASE

WHEN IFNULL(SUM(`RCV Time Active`),0)=0

THEN 0

ELSE

(SUM(`RCV Number of Lines`)/SUM(`RCV Time Active`))/`RCV Standard - Dynamic`

END)

END

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-10-2017
11:02 AM

10-10-2017
11:02 AM

Another option is to do a nested CASE statement to account for the divide by zero in both divisors:

CASE

WHEN IFNULL(`Standard`,0) = 0 THEN 0

ELSE

(*CASE **WHEN IFNULL(`Hours Active`,0) = 0 THEN 0**ELSE (IFNULL(Number of Lines,0) / IFNULL(Hours Active,0))**END*) / IFNULL(`Standard`,0)

END

Brett

**Say "Thanks" by clicking the "heart" in the post that helped you.

**Please mark the post that solves your problem by clicking on "Accept as Solution"

**Say "Thanks" by clicking the "heart" in the post that helped you.

**Please mark the post that solves your problem by clicking on "Accept as Solution"

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-10-2017
04:09 AM

10-10-2017
04:09 AM

Hi.

Please try using nullif and ifnull.

**Original**

(Number of Lines / Hours Active) / Standard

**Standard = 0 -> null**

(Number of Lines / Hours Active) / nullif(Standard,0)

**0 or null -> 0**

ifnull((Number of Lines / Hours Active) / nullif(Standard,0),0)

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-10-2017
04:50 AM

10-10-2017
04:50 AM

I've tried a few times without success to change my existing Beast Mode to include what you've suggested and I cannot get it to work. Can you show me the completed Beast Mode instead of just those suggested lines please?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-10-2017
05:41 AM

10-10-2017
05:41 AM

Hi @swagner,

If I correctly understood your problem... Have you tried using just nullif? Divisions by 0 do raise an error but division by null equals null (This is what I systematically use), so in your case, I would go with :

**(Number of Lines / NULLIF(Hours Active,0)) / NULLIF(Standard,0)**

This way no divisor will ever be zero.

In the end, you can always revert to zero if the result is null (I do not agree with this approach as a division by zero tends to an infinite number, not a zero! But some people follow this)

**IFNULL((Number of Lines / NULLIF(Hours Active,0)) / NULLIF(Standard,0),0)**

Hope this helps.

**Ricardo Granada**

MajorDomo@Lusiaves

**If the post solves your problem, mark it by clicking on "Accept as Solution"

**You can say "Thank you" by clicking the thumbs up in the post that helped you.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-10-2017
11:02 AM

10-10-2017
11:02 AM

Another option is to do a nested CASE statement to account for the divide by zero in both divisors:

CASE

WHEN IFNULL(`Standard`,0) = 0 THEN 0

ELSE

(*CASE **WHEN IFNULL(`Hours Active`,0) = 0 THEN 0**ELSE (IFNULL(Number of Lines,0) / IFNULL(Hours Active,0))**END*) / IFNULL(`Standard`,0)

END

Brett

**Say "Thanks" by clicking the "heart" in the post that helped you.

**Please mark the post that solves your problem by clicking on "Accept as Solution"

**Say "Thanks" by clicking the "heart" in the post that helped you.

**Please mark the post that solves your problem by clicking on "Accept as Solution"

Highlighted
##
##### Re: Beast Mode Help: Two layers of division

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-10-2017
09:29 PM

10-10-2017
09:29 PM

I forgot to nullif to "Hours Active".

**Original**

(Number of Lines / Hours Active) / Standard

**Standard = 0 -> null**

(Number of Lines / nullif(Hours Active,0)) / nullif(Standard,0)

or

(sum(Number of Lines) / nullif(sum(Hours Active),0)) / nullif(sum(Standard),0)

**0 or null -> 0**

ifnull((Number of Lines / nullif(Hours Active,0)) / nullif(Standard,0),0)

or

ifnull((sum(Number of Lines) / nullif(sum(Hours Active),0)) / nullif(sum(Standard),0),0)

Announcements