Reconcile three revenue totals with a bridge

short · 40 min · Objective 3.3

Task

Calculate three different revenue totals from the same orders, each defensible, and build the bridge that explains exactly how they differ.

Steps

  1. From data/orders.csv and data/products.csv, calculate: gross revenue for orders with a positive quantity (quantity times unit price); net revenue for the same orders (after discount); and net revenue for all rows, negative quantities included.
  2. Record them in lab/recon/totals.txt as gross valid: N, net valid: N and net all: N, to two decimal places.
  3. Record the two bridge steps as discounts: N (gross valid minus net valid) and negative rows: N (net valid minus net all).

Verify

These checks run in a POSIX shell with Python 3: Terminal on macOS or Linux, and on Windows Git Bash (it comes with Git for Windows) or WSL. On Windows, python3 is often a Microsoft Store placeholder that prints “Python was not found”; run alias python3=py in Git Bash first.

grep -E '^(gross valid|net valid|net all|discounts|negative rows): ' lab/recon/totals.txt
awk -F': ' '/^gross/ {g=$2} /^net all/ {a=$2} /^discounts/ {d=$2} /^negative/ {n=$2} END {printf "bridge closes: %s%s", ((g-d-n)-a < 0.01 && a-(g-d-n) < 0.01) ? "yes" : "no", ORS}' lab/recon/totals.txt

369681.37 gross, 354627.14 net of discounts and 353816.74 with every row; discounts of 15054.24 and negative rows of 810.39 bridge the gap exactly. (Subtracting the rounded totals instead gives 15054.23 and 810.40: a cent of rounding, not a discrepancy.) Three figures, one data set, no arithmetic errors -- only three definitions.

This is an independent study companion for CompTIA Data+ DA0-002 and is not produced by or endorsed by CompTIA.