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
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 616 Datasets
- 2.2K Magic ETL
- 3.8K Visualize
- 2.5K Charting
- 737 Beast Mode
- 56 App Studio
- 40 Variables
- 684 Automate
- 176 Apps
- 452 APIs & Domo Developer
- 46 Workflows
- 10 DomoAI
- 35 Predict
- 14 Jupyter Workspaces
- 21 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 123 Manage
- 120 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive