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
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 %?

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 0END))
    /
    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 to <3 any users posts that helped you.
    **Please mark as accepted the ones who solved your issue.
  • ArborRose
    ArborRose Coach
    edited June 25

    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! **