Using Variables in Beast Mode
![kevin_johnson](https://us.v-cdn.net/6032830/uploads/defaultavatar/nZ5X977MOM3Z6.jpg)
Hi all,
I'm trying to write a Beast Mode and it would be much easier if I could declare a variable to make my code a bit simpler. I would want to do something like this:
CASE
WHEN `Date of Death` is NULL THEN FLOOR(DATEDIFF(CURRENT_DATE(), `Date of Birth`)/365)
ELSE FLOOR(DATEDIFF(`Date of Death`, `Date of Birth`)/365)
END AS AGE,
CASE
WHEN AGE < 1 THEN '>1'
WHEN AGE BETWEEN 1 AND 3 THEN '1-3'
WHEN AGE BETWEEN 4 AND 6 THEN '3-6'
WHEN AGE BETWEEN 7 AND 9 THEN '7-9'
WHEN AGE BETWEEN 10 AND 12 THEN '10-12'
WHEN AGE BETWEEN 13 AND 15 THEN '13-15'
WHEN AGE BETWEEN 16 AND 18 THEN '16-18'
ELSE '18+'
END
But this code isn't running for me.
So I was wondering if the issue is my declaring the variable or if there's some other issue with the code.
Thanks in advance!
Best Answer
-
Yes, you can't create a "variable" in a beast mode and try and reference it later in your beast mode. Domo is working on functionality to allow you to nest beast modes, so you could create a beast mode called age and then in your age range beast mode you could reference the age beast mode.
Your workaround right now would be to calculate the age in an ETL so that it is a field in your dataset, or rework your case statement to do your age calculation in each when clause.
**Check out my Domo Tips & Tricks Videos
**Make sure toany users posts that helped you.
**Please mark as accepted the ones who solved your issue.0
Answers
-
Yes, you can't create a "variable" in a beast mode and try and reference it later in your beast mode. Domo is working on functionality to allow you to nest beast modes, so you could create a beast mode called age and then in your age range beast mode you could reference the age beast mode.
Your workaround right now would be to calculate the age in an ETL so that it is a field in your dataset, or rework your case statement to do your age calculation in each when clause.
**Check out my Domo Tips & Tricks Videos
**Make sure toany users posts that helped you.
**Please mark as accepted the ones who solved your issue.0 -
Here's a re-worked case statement:
CASE
WHENDate of Death
is NULL THEN FLOOR(DATEDIFF(CURRENT_DATE(),Date of Birth
)/365)
WHEN FLOOR(DATEDIFF(Date of Death
,Date of Birth
)/365) < 1 THEN '<1'
WHEN FLOOR(DATEDIFF(Date of Death
,Date of Birth
)/365) < 3 THEN '1-3'
WHEN FLOOR(DATEDIFF(Date of Death
,Date of Birth
)/365) < 6 THEN '3-6'
WHEN FLOOR(DATEDIFF(Date of Death
,Date of Birth
)/365) < 9 THEN '7-9'
WHEN FLOOR(DATEDIFF(Date of Death
,Date of Birth
)/365) < 12 THEN '10-12'
WHEN FLOOR(DATEDIFF(Date of Death
,Date of Birth
)/365) < 15 THEN '13-15'
WHEN FLOOR(DATEDIFF(Date of Death
,Date of Birth
)/365) < 18 THEN '16-18'
ELSE '18+'
ENDDue to how case statement functions, you are able to remove the between logic and just use less than logic which makes the statement a bit more concise.
Hope this helps.
**Check out my Domo Tips & Tricks Videos
**Make sure toany users posts that helped you.
**Please mark as accepted the ones who solved your issue.2
Categories
- All Categories
- 1.9K Product Ideas
- 1.9K Ideas Exchange
- 1.6K Connect
- 1.3K Connectors
- 303 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 3K Transform
- 104 SQL DataFlows
- 640 Datasets
- 2.2K Magic ETL
- 4K Visualize
- 2.5K Charting
- 769 Beast Mode
- 72 App Studio
- 43 Variables
- 718 Automate
- 185 Apps
- 462 APIs & Domo Developer
- 57 Workflows
- 14 DomoAI
- 40 Predict
- 17 Jupyter Workspaces
- 23 R & Python Tiles
- 402 Distribute
- 116 Domo Everywhere
- 277 Scheduled Reports
- 9 Software Integrations
- 135 Manage
- 132 Governance & Security
- 8 Domo Community Gallery
- 44 Product Releases
- 12 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 111 Community Announcements
- 4.8K Archive