Allocate one carrier bill to two lines
Three eligible order lines share a $10 carrier charge equally.
The interview prompt
Three eligible order lines share a $10 carrier charge equally. The result must be in whole cents, remain stable on rerun, and reconcile to the original invoice. Which line gets the extra cent?
Make rounding as reproducible as the allocation
Calculate the pool in integer cents. With three equal weights, each exact share is 333⅓ cents. The floor of each share is 333 cents, leaving a one-cent residual. One defensible rule distributes residual cents in descending order of fractional remainder, breaking ties by stable line ID. Under ascending IDs A, B, and C, the results are $3.34, $3.33, and $3.33. Changing database row order should not move a cent between lines.
For unequal weights, retain the original driver values and identify which lines were eligible before rounding. Compare their sum with the denominator used. If all weights are zero, division is undefined. Record an unallocated pool or use a business-approved fallback with a distinct rule version. Avoid silently assigning the charge to whichever line was loaded first.
A result can reconcile to the cent while answering the wrong economic question. A flat per-parcel carrier fee might be split by weight for financial reporting. To decide whether to add a book to an already-paid parcel, you need the incremental charge under the actual tariff. Carry the invoice reference through both analyses and explain which costs were observed and which shares were assigned.
The model behind the answer
Suppose a different order contains a book and a classroom map. The carrier bills $15 for the parcel. The packed items weigh one and four kilograms. The invoice establishes parcel cost. It says nothing about either line’s individual cost.
If Maya approves weight as the allocation basis, the lines receive $3 and $12. Keep the invoice-line identity, the input weights, the rule version, and any rounding treatment with the result. Reconcile the allocated $15 back to the billed $15. When weights are missing, expose the unassigned amount or apply an agreed fallback. A tidy zero would make missing evidence look like free freight.
The warehouse may split costs by weight while a pricing analyst wants the incremental cost of adding one more book. Those are different questions. The carrier’s pricing curve might make the extra book nearly free. A defensible allocation answers how the company distributed a charge and leaves the marginal-cost question visible. Kimball on allocated facts · Why Unit Economics?
Try it in SQLite
Account for the final cent
Split 1,000 cents among three lines. Compare independent rounding with a deterministic remainder rule, then change the weights.
Tables and sample data
Each run starts with fresh sample data. Use Ctrl+Enter or ⌘+Enter to run. Only your browser processes the query.
Review the residual cent as a release decision
Ask the agent to implement the approved allocation in integer cents and show the allocation rule version on each line. A reviewer shuffles the three equally weighted lines before rerunning the $10 fixture.
Reviewer decision. A, B and C must receive 334, 333 and 333 cents under the stated tie-break. Then set all weights to zero. The whole 1,000 cents must remain accounted for under the agreed exception policy. Finance chooses the driver and the fallback. Passing a sum check alone cannot settle either decision.
Further reading. The Data Warehouse Toolkit, 3rd ed., on allocating header charges using business rules.
One more question
The carrier later issues a $1 credit. Recompute the original allocation or record the credit separately?
Check your reasoning
Preserve the original invoice and credit identities. A current net-cost view may reallocate the $9 net pool under its rule. An issued period report may require an explicit credit and a new adjustment allocation. Test that each document and the net position reconcile under the chosen policy.
Previous · Compare shipments and refunds without multiplying either · Next · Give a correction somewhere to go · Complete series map