Help for nested case statement in beast mode
I have these two measures made in beast mode that looks like this:
Status
CASE WHEN `Delivery` = 'Done' THEN 'Complete'
ELSE CASE WHEN IFNULL(`Quantity`, 0) < IFNULL(`Order Quantity`,0) THEN 'Pending' ELSE 'Complete
END
Completion Percentage
(
COUNT(DISTINCT
CASE WHEN `Delivery` = 'Done' THEN CONCAT(`Company Code`, `Purchase Code`, 'Customer Code`)
ELSE CASE WHEN IFNULL(`Quantity`,0) = `Order Quantity` THEN CONCAT(`Company Code`, `Purchase Code`, 'Customer Code`) END
END)
)
/
COUNT(DISTINCT CASE WHEN IFNULL(`Quantity`,0) < `Order Quantity` THEN CONCAT(`Company Code`, `Purchase Code`, 'Customer Code`) END)
Now the problem is that as you can see, the calculation for Completion Percentage only includes Case when `Delivery` =`Done`, while in the Status, the 'Complete` status also includes the Else condition. So how do I modify the code in Completion Percentage so that the Delivery also includes the Else condition like the one in the Status?
Thanks!
Comments
-
So a bit cleaner version of the Status calculation would look like this:
CASE WHEN `Delivery` = 'Done' THEN 'Complete'
WHEN IFNULL(`Quantity`, 0) < IFNULL(`Order Quantity`,0) THEN 'Pending'
ELSE 'Complete'
ENDNo need to nest the case statement here. And actually you could make it like this as well:
CASE WHEN IFNULL(`Quantity`, 0) < IFNULL(`Order Quantity`,0)
AND `Delivery` <> 'Done'
THEN 'Pending'
ELSE 'Complete'
ENDAnd for your completion percentage calc, I'm assuming you're wanting the percentage of all 'items' that are below order quantity with a status of Complete. That would look like this:
1 -
(
COUNT(DISTINCT CASE WHEN IFNULL(`Quantity`, 0) < IFNULL(`Order Quantity`,0)
AND `Delivery` <> 'Done'
THEN CONCAT(`Company Code`, `Purchase Code`, 'Customer Code`)
END
)
/
COUNT(DISTINCT CASE WHEN IFNULL(`Quantity`,0) < `Order Quantity` THEN CONCAT(`Company Code`, `Purchase Code`, 'Customer Code`) END)That code finds the % pending (the inverse of completion %) and does 1 - that value to give you completion.
Hope that helps you get what you're looking for,
Valiant
**Please mark "Accept as Solution" if this post solves your problem
**Say "Thanks" by clicking the "heart" in the post that helped you.1 -
Just from a best practices approach, I would recommend moving the `Status` beast mode into the data set.
The advantage to placing any sort of "Classification" calculations directly into the data set is that you can then use that field in page filters as well as other beast modes.
The Status calculation here is simply classifying each line of data by looking at the values of a few other fields in that line. If there is no aggregation needed to define `Status`, or any other classification field, then there is no need to use a beast mode to calculate it.
The completion percentage is a great use case for a beastmode as the beastmode will recalculate every time that you filter and slice the data a new way (by area, or quarter, etc)
0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.6K Connect
- 1.2K Connectors
- 302 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 104 SQL DataFlows
- 633 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 760 Beast Mode
- 62 App Studio
- 42 Variables
- 699 Automate
- 181 Apps
- 457 APIs & Domo Developer
- 51 Workflows
- 10 DomoAI
- 38 Predict
- 16 Jupyter Workspaces
- 22 R & Python Tiles
- 401 Distribute
- 116 Domo Everywhere
- 277 Scheduled Reports
- 8 Software Integrations
- 130 Manage
- 127 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 12 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 111 Community Announcements
- 4.8K Archive