Beast Mode to Categorize the data based upon the pattern

Hello,
Can anyone help me in writing this beast mode. Where I'm aiming to categorize these based on the status reversals from Yes to No.
Case when current ready status is No and previous status is Yes then considered as reversal.
Example like below: I already have first 3 columns in my data.
Tried this beast mode but not working.
CASE
WHEN SUM(CASE
WHEN `Ready Status` = 'No'
AND `Previous Ready Status` = 'Yes'
AND `Previous Ready Status` IS NOT NULL
THEN 1
ELSE 0
END)
OVER (PARTITION BY `Case Number` ORDER BY `Case Number`) = 1 THEN '1 Time'
WHEN SUM(CASE
WHEN `Ready Status` = 'No'
AND `Previous Ready Status` = 'Yes'
AND `Previous Ready Status` IS NOT NULL
THEN 1
ELSE 0
END)
OVER (PARTITION BY `Case Number` ORDER BY `Case Number`) = 2 THEN '2 Times'
WHEN SUM(CASE
WHEN `Ready Status` = 'No'
AND `Previous Ready Status` = 'Yes'
AND `Previous Ready Status` IS NOT NULL
THEN 1
ELSE 0
END)
OVER (PARTITION BY `Case Number` ORDER BY `Case Number`) >= 3 THEN '3+ Times'
ELSE 'No Reversal'
END
Best Answer
-
Hi - your original beast mode was missing the second aggregation, you needed SUM(SUM(…
CASE
WHEN SUM(SUM(CASE
WHEN `Ready Status` = 'No'
AND `Previous Ready Status` = 'Yes'
AND `Previous Ready Status` IS NOT NULL
THEN 1
ELSE 0
END))
OVER (PARTITION BY `Case Number` ORDER BY `Case Number`) = 1 THEN '1 Time'
WHEN SUM(SUM(CASE
WHEN `Ready Status` = 'No'
AND `Previous Ready Status` = 'Yes'
AND `Previous Ready Status` IS NOT NULL
THEN 1
ELSE 0
END))
OVER (PARTITION BY `Case Number` ORDER BY `Case Number`) = 2 THEN '2 Times'
WHEN SUM(SUM(CASE
WHEN `Ready Status` = 'No'
AND `Previous Ready Status` = 'Yes'
AND `Previous Ready Status` IS NOT NULL
THEN 1
ELSE 0
END))
OVER (PARTITION BY `Case Number` ORDER BY `Case Number`) >= 3 THEN '3+ Times'
ELSE 'No Reversal'
ENDbut also, I feel that you can get the same result without the window function
CASE
WHEN SUM(CASE WHEN `ready status` = 'No' AND `previous ready status` = 'Yes' THEN 1 END) = 1 THEN '1 Time'
WHEN SUM(CASE WHEN `ready status` = 'No' AND `previous ready status` = 'Yes' THEN 1 END) = 2 THEN '2 Times'
WHEN SUM(CASE WHEN `ready status` = 'No' AND `previous ready status` = 'Yes' THEN 1 END) > 2 THEN '3+ Times'
ELSE 'No Reversal'
END0
Answers
-
Hey Agolla,
I think that a beastmode is not the best suited tool for this task.
Try the following in magic ETL:
- Group by Case number, count case status that equal "Yes" and count case status that equal "No"
2. Then, take the minimum of both these. This will give you the total number of reversals, assuming there are an even number plus one of yes and nos.
0 -
You can also do this in a pivot table if magic etl is not an option.
0 -
Ok, thanks for the response.
But I have added a new column (Reversal Status) beside each row whether it is a reversal or not (Yes/No).Case Number
Reversal Status
123
Yes
123
Yes
341
No
341
Yes
Now can I count how many 1,2, 3+ times for each case?
I need a single value of sum of cases where only 1 reversal occurred and likewise for 2, and 3+ times0 -
Hi - your original beast mode was missing the second aggregation, you needed SUM(SUM(…
CASE
WHEN SUM(SUM(CASE
WHEN `Ready Status` = 'No'
AND `Previous Ready Status` = 'Yes'
AND `Previous Ready Status` IS NOT NULL
THEN 1
ELSE 0
END))
OVER (PARTITION BY `Case Number` ORDER BY `Case Number`) = 1 THEN '1 Time'
WHEN SUM(SUM(CASE
WHEN `Ready Status` = 'No'
AND `Previous Ready Status` = 'Yes'
AND `Previous Ready Status` IS NOT NULL
THEN 1
ELSE 0
END))
OVER (PARTITION BY `Case Number` ORDER BY `Case Number`) = 2 THEN '2 Times'
WHEN SUM(SUM(CASE
WHEN `Ready Status` = 'No'
AND `Previous Ready Status` = 'Yes'
AND `Previous Ready Status` IS NOT NULL
THEN 1
ELSE 0
END))
OVER (PARTITION BY `Case Number` ORDER BY `Case Number`) >= 3 THEN '3+ Times'
ELSE 'No Reversal'
ENDbut also, I feel that you can get the same result without the window function
CASE
WHEN SUM(CASE WHEN `ready status` = 'No' AND `previous ready status` = 'Yes' THEN 1 END) = 1 THEN '1 Time'
WHEN SUM(CASE WHEN `ready status` = 'No' AND `previous ready status` = 'Yes' THEN 1 END) = 2 THEN '2 Times'
WHEN SUM(CASE WHEN `ready status` = 'No' AND `previous ready status` = 'Yes' THEN 1 END) > 2 THEN '3+ Times'
ELSE 'No Reversal'
END0
Categories
- All Categories
- 2K Product Ideas
- 2K Ideas Exchange
- 1.6K Connect
- 1.3K Connectors
- 311 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 3.8K Transform
- 656 Datasets
- 115 SQL DataFlows
- 2.2K Magic ETL
- 813 Beast Mode
- 3.3K Visualize
- 2.5K Charting
- 81 App Studio
- 45 Variables
- 771 Automate
- 190 Apps
- 481 APIs & Domo Developer
- 77 Workflows
- 23 Code Engine
- 36 AI and Machine Learning
- 19 AI Chat
- AI Playground
- AI Projects and Models
- 17 Jupyter Workspaces
- 410 Distribute
- 120 Domo Everywhere
- 280 Scheduled Reports
- 10 Software Integrations
- 142 Manage
- 138 Governance & Security
- 8 Domo Community Gallery
- 48 Product Releases
- 12 Domo University
- 5.4K Community Forums
- 41 Getting Started
- 31 Community Member Introductions
- 114 Community Announcements
- 4.8K Archive