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
- :
- Beast Mode Case Statement Help

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

Highlighted

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

01-08-2018
08:58 AM

01-08-2018
08:58 AM

For some reason this CASE statement will not validate. I have all the required parts. `PayTotal` and `PayTargetWeek` are both number values and I want this field to return a character string.

case when (sum(`PayTotal`) / `PayTargetWeek`) <= -.05 then 'Under Target'

when (sum(`PayTotal`) / `PayTargetWeek`) >= -.049 and <= .05 then 'On Target'

when (sum(`PayTotal`) / `PayTargetWeek`) >= .051 then 'Above Target'

else 'Not Sure'

end

Chad Bishop

Data Analyst

Bolt Express

Data Analyst

Bolt Express

Labels:

Accepted Solutions

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

01-08-2018
09:07 AM

01-08-2018
09:07 AM

I also tried writing it this way but again...it will *not* resolve/validate.

case when (sum(`PayTotal`) / (CASE when `PayTargetWeek` = 0 then 1 end)) <= -.05 then 'Under Target'

when (sum(`PayTotal`) / (CASE when `PayTargetWeek` = 0 then 1 end)) >= -.049 and <= .05 then 'On Target'

when (sum(`PayTotal`) / (CASE when `PayTargetWeek` = 0 then 1 end)) >= .051 then 'Above Target'

else 'Not Sure'

end

Chad Bishop

Data Analyst

Bolt Express

Data Analyst

Bolt Express

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

01-08-2018
10:05 AM

01-08-2018
10:05 AM

Hi Chad

Generally speaking, beast modes with aggregations within case statements are pretty tricky.

Why are you summing PayTotal but not aggregating PayTargetWeek? What your beast mode is doing is adding up a bunch of rows to get the sum of PayTotal, but then comparing the aggregation against a single row's PayTargetWeek value. Comparing aggregates against single rows does not usually work like you want or expect. Is PayTargetWeek the same value for every row that PayTotal is being summed on? Like, a single row of data has an individual PayTotal for a day or person or something but then it also has a wider PayTargetWeek value, that's not the same granularity? You can get around that by averaging your PayTargetWeek value in the denominator (assuming different granularities)

Also, you are missing something in your second comparison. Each comparison needs two values. Your "<= .05" comparison lacks the first value. The aggregation can't carry over. You'll have to compute that aggregation fully in each comparison.

In addition, there might be values between -.05 and -.049, or .05 and .051, so your would need to adjust the operators to leave no gaps. This won't make your beast mode validate, but it makes the results more usable.

Try this and see what happens:

*case *

*when sum(`PayTotal`) / AVG(`PayTargetWeek`) <= -.05 then 'Under Target'**when sum(`PayTotal`) / AVG(`PayTargetWeek`) > -.05 and sum(`PayTotal`) / AVG(`PayTargetWeek`) <= .05 then 'On Target'**when sum(`PayTotal`) / AVG(`PayTargetWeek`) > .05 then 'Above Target'**else 'Not Sure'**end*

Aaron

MajorDomo @ Merit Medical

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

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

MajorDomo @ Merit Medical

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

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

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

01-08-2018
11:09 AM

01-08-2018
11:09 AM

By the time I opened this thread, SUM(`PayTotal`) was just a troubleshooting-itteration of the case() statement I was trying to make work.

I took your suggestion and modified it slightly to:

case

when `PayTotal` / `PayTargetWeek` <= -.05 then 'Under Target'

when `PayTotal` / `PayTargetWeek` > -.05 and `PayTotal` / `PayTargetWeek` <= .05 then 'On Target'

when `PayTotal` / `PayTargetWeek` > .05 then 'Above Target'

else 'Not Sure'

end

I did this becuase ultimately I didn't need to SUM(`PayTotal`). I removed the AVG() from PayTargetWeek as well.

In the end, the error that was causing the BeastMode to fail validation was the second evalaution in the case, "when `PayTotal` / `PayTargetWeek` > -.05 and `PayTotal` / `PayTargetWeek` <= .05 then 'On Target' ". Once I added this, Validation Passed.

Thank you all for the assist and explanations.

Chad Bishop

Data Analyst

Bolt Express

Data Analyst

Bolt Express

All Replies

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

01-08-2018
09:01 AM

01-08-2018
09:01 AM

You'll need to add a check for divide by 0 possibility.

Try this:

CASE WHEN `PayTargetWeek` = 0 THEN 1 ELSE

case when (sum(`PayTotal`) / `PayTargetWeek`) <= -.05 then 'Under Target'

when (sum(`PayTotal`) / `PayTargetWeek`) >= -.049 and <= .05 then 'On Target'

when (sum(`PayTotal`) / `PayTargetWeek`) >= .051 then 'Above Target'

else 'Not Sure'

end

END

Hopefully that should work for you.

Sincerely,

Colt

**Please mark "Accept as Solution" if this post solves your problem

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

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

01-08-2018
09:05 AM

01-08-2018
09:05 AM

Thanks for the quick response...however, this will still *not* resolve.

CASE when `PayTargetWeek` = 0 then 1 ELSE

case when (sum(`PayTotal`) / `PayTargetWeek`) <= -.05 then 'Under Target'

when (sum(`PayTotal`) / `PayTargetWeek`) >= -.049 and <= .05 then 'On Target'

when (sum(`PayTotal`) / `PayTargetWeek`) >= .051 then 'Above Target'

else 'Not Sure'

end

END

Chad Bishop

Data Analyst

Bolt Express

Data Analyst

Bolt Express

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

01-08-2018
09:07 AM

01-08-2018
09:07 AM

I also tried writing it this way but again...it will *not* resolve/validate.

case when (sum(`PayTotal`) / (CASE when `PayTargetWeek` = 0 then 1 end)) <= -.05 then 'Under Target'

when (sum(`PayTotal`) / (CASE when `PayTargetWeek` = 0 then 1 end)) >= -.049 and <= .05 then 'On Target'

when (sum(`PayTotal`) / (CASE when `PayTargetWeek` = 0 then 1 end)) >= .051 then 'Above Target'

else 'Not Sure'

end

Chad Bishop

Data Analyst

Bolt Express

Data Analyst

Bolt Express

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

01-08-2018
10:05 AM

01-08-2018
10:05 AM

Hi Chad

Generally speaking, beast modes with aggregations within case statements are pretty tricky.

Why are you summing PayTotal but not aggregating PayTargetWeek? What your beast mode is doing is adding up a bunch of rows to get the sum of PayTotal, but then comparing the aggregation against a single row's PayTargetWeek value. Comparing aggregates against single rows does not usually work like you want or expect. Is PayTargetWeek the same value for every row that PayTotal is being summed on? Like, a single row of data has an individual PayTotal for a day or person or something but then it also has a wider PayTargetWeek value, that's not the same granularity? You can get around that by averaging your PayTargetWeek value in the denominator (assuming different granularities)

Also, you are missing something in your second comparison. Each comparison needs two values. Your "<= .05" comparison lacks the first value. The aggregation can't carry over. You'll have to compute that aggregation fully in each comparison.

In addition, there might be values between -.05 and -.049, or .05 and .051, so your would need to adjust the operators to leave no gaps. This won't make your beast mode validate, but it makes the results more usable.

Try this and see what happens:

*case *

*when sum(`PayTotal`) / AVG(`PayTargetWeek`) <= -.05 then 'Under Target'**when sum(`PayTotal`) / AVG(`PayTargetWeek`) > -.05 and sum(`PayTotal`) / AVG(`PayTargetWeek`) <= .05 then 'On Target'**when sum(`PayTotal`) / AVG(`PayTargetWeek`) > .05 then 'Above Target'**else 'Not Sure'**end*

Aaron

MajorDomo @ Merit Medical

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

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

MajorDomo @ Merit Medical

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

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

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

01-08-2018
11:09 AM

01-08-2018
11:09 AM

By the time I opened this thread, SUM(`PayTotal`) was just a troubleshooting-itteration of the case() statement I was trying to make work.

I took your suggestion and modified it slightly to:

case

when `PayTotal` / `PayTargetWeek` <= -.05 then 'Under Target'

when `PayTotal` / `PayTargetWeek` > -.05 and `PayTotal` / `PayTargetWeek` <= .05 then 'On Target'

when `PayTotal` / `PayTargetWeek` > .05 then 'Above Target'

else 'Not Sure'

end

I did this becuase ultimately I didn't need to SUM(`PayTotal`). I removed the AVG() from PayTargetWeek as well.

In the end, the error that was causing the BeastMode to fail validation was the second evalaution in the case, "when `PayTotal` / `PayTargetWeek` > -.05 and `PayTotal` / `PayTargetWeek` <= .05 then 'On Target' ". Once I added this, Validation Passed.

Thank you all for the assist and explanations.

Chad Bishop

Data Analyst

Bolt Express

Data Analyst

Bolt Express