Count and Percentage of On-Time shipments per Distinct Document

Hi, I'm new to Domo and struggling to figure out what I think should be a pretty simple calculation. I am trying to figure out on-time delivery percentages for sales orders that have shipped. I have a transactional dataset with multiple rows of data per order (or document_number) and I'm trying to avoid having to modify the ETL or making a new dataset. I have a beast mode called SO OTD Tag with that tags each line as 'On-Time', 'Late', 'Past-Due', or 'Open' as shown below:
CASE
WHENtype
= 'SalesOrd' THEN
CASE
WHENactualshipdate
IS NULL THEN
CASE
WHENrequested_shipdate
< CURDATE() THEN 'Past-Due'
WHENrequested_shipdate
>= CURDATE() THEN 'Open'
END
WHENactualshipdate
IS NOT NULL THEN
CASE
WHENactualshipdate
>requested_shipdate
THEN 'Late'
WHENactualshipdate
<=requested_shipdate
THEN 'On-Time'
END
END
END
Now that I have tagged all sales orders, I want to group by distinct sales order and count whether the sales order is late or not, then divide this by the total number shipped (On-Time SOs + Late SOs). Again, each sales order has multiple lines within the dataset. Currently, I have a draft of OTD % shown in the below code block:
(COUNT(CASE WHEN `SO OTD Tag` = 'On-Time' THEN 1 END))
/
COUNT(`document_number`)
This calculation doesn't necessarily work because it calculates based on the number of lines, not the number of distinct sales orders (or 'document_number').
Any way I can group by documentnumber and assign an OTD tag for each individual document_number and get an OTD %?
Answers
-
I'm having a hard time visualizing your data so my initial answer may not be what you are looking for. If you have an order with 4 items in the order and 3 are tagged as On-Time based on your initial beast mode, then that should yield a percentage of 75%.
Given that, I would suggest you alter your 2nd beast mode to to be the following:
(SUM(
CASE
WHEN
`SO OTD Tag` = 'On-Time'
THEN
1 ELSE 0
END
))
/
COUNT(`document_number`)
If you use a table chart and then place the document and this 2nd beast mode in your card, I believe you should get that percentage.
**Check out my Domo Tips & Tricks Videos
**Make sure toany users posts that helped you.
**Please mark as accepted the ones who solved your issue.0 -
It sounds like you want to calculate on-time deliver percent on sales orders (document /order number), not lines. Your beast mode tags each line as on-time, late, or whatever - rather than each order.
You probably may need something with a FIXED()CASE
WHEN MAX(CASE WHEN `SO OTD Tag` = 'Late' THEN 1 ELSE 0 END) OVER (PARTITION BY `document_number`) = 1 THEN 'Late'
WHEN MIN(CASE WHEN `SO OTD Tag` = 'On-Time' THEN 1 ELSE 0 END) OVER (PARTITION BY `document_number`) = 1 THEN 'On-Time'
ELSE 'Other'
END
COUNT(DISTINCT CASE WHEN `Order OTD Status` = 'On-Time' THEN `document_number` END)
/
COUNT(DISTINCT CASE WHEN `Order OTD Status` IN ('On-Time', 'Late') THEN `document_number` END)As Mark mentioned…it would be helpful to see a few rows of anonymized data.
** Was this post helpful? Click Agree or Like below. **
** Did this solve your problem? Accept it as a solution! **0
Categories
- All Categories
- Product Ideas
- 2.1K Ideas Exchange
- Connect
- 1.3K Connectors
- 309 Workbench
- 7 Cloud Amplifier
- 10 Federated
- Transform
- 665 Datasets
- 120 SQL DataFlows
- 2.3K Magic ETL
- 827 Beast Mode
- Visualize
- 2.6K Charting
- 90 App Studio
- 46 Variables
- Automate
- 198 Apps
- 489 APIs & Domo Developer
- 97 Workflows
- 24 Code Engine
- AI and Machine Learning
- 23 AI Chat
- 4 AI Projects and Models
- 18 Jupyter Workspaces
- Distribute
- 119 Domo Everywhere
- 284 Scheduled Reports
- 11 Software Integrations
- Manage
- 145 Governance & Security
- 13 Domo Community Gallery
- 49 Product Releases
- 13 Domo University
- Community Forums
- 41 Getting Started
- 31 Community Member Introductions
- 117 Community Announcements
- 5K Archive