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.6K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 102 SQL DataFlows
- 626 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 753 Beast Mode
- 61 App Studio
- 41 Variables
- 692 Automate
- 177 Apps
- 456 APIs & Domo Developer
- 49 Workflows
- 10 DomoAI
- 38 Predict
- 16 Jupyter Workspaces
- 22 R & Python Tiles
- 398 Distribute
- 115 Domo Everywhere
- 276 Scheduled Reports
- 7 Software Integrations
- 130 Manage
- 127 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 11 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 110 Community Announcements
- 4.8K Archive