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
WHEN type
= 'SalesOrd' THEN
CASE
WHEN actualshipdate
IS NULL THEN
CASE
WHEN requested_shipdate
< CURDATE() THEN 'Past-Due'
WHEN requested_shipdate
>= CURDATE() THEN 'Open'
END
WHEN actualshipdate
IS NOT NULL THEN
CASE
WHEN actualshipdate
> requested_shipdate
THEN 'Late'
WHEN actualshipdate
<= 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 %?