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
- Product Ideas
- 2.1K Ideas Exchange
- Data Connections
- 1.3K Connectors
- 309 Workbench
- 17 Cloud Integrations
- Data & ETL
- 2.3K Magic ETL
- 120 SQL DataFlows
- 666 Datasets
- Visualize & Apps
- 90 App Studio
- 198 Pro-code Components
- 2.6K Charting & Analyzer
- 873 Calculations & Variables (Beast Mode)
- AI & Data science
- 23 Domo AI & AI Chat
- 4 Managing AI
- 18 Jupyter Workspaces
- Automate
- 122 Workflows
- Alerts
- Distribute
- 118 Domo Everywhere
- 284 Reporting
- Manage
- 145 Governance & Security
- 489 APIs
- 11 Add-ins & Plugins
- 13 Domo Community Gallery
- 49 Product Releases
- 13 Domo University
- Community Forums
- 41 Getting Started
- 31 Community Member Introductions
- 118 Community Announcements
- 5K Archive