Ir para o conteúdo

Lição 24 · Projects and Reference

Project: A Weekly Sales Summary

Build a weekly sales summary from brief to delivery: define metrics, query two weeks in SQL, check the totals, then generate a table and written findings in Python.

In this project you build a complete weekly sales report for an invented online shop. You will move through the workflow from earlier lessons: brief, definitions, query, checks, formatting and findings. Work through each step, then change the data and see whether your report still tells the truth.

Step 1: The brief

TEXT
Readers:   Sales lead and two team managers
Decision:  Where to focus follow-up work next week
Rhythm:    Monday morning, data through Sunday (UTC)
Questions: How much did we sell, compared with last week and target?
           Which category explains the change?
Not included: Profit, marketing cost, forecasts

Step 2: Definitions

  • Net sales: amount of orders with status paid, minus refunds recorded on the same row. Test orders are excluded. (This small data set keeps refunds on the order row. A real system may date refunds separately.)
  • Orders: count of paid, non-test orders.
  • Average order value (AOV): net sales divided by orders.
  • Week: Monday through Sunday, identified by its Monday.
  • Target: 1,500 net sales per week (invented).

Step 3: Query

The query defines both weeks once, applies the rules once and returns one row per week and category.

SQL Net sales by week and category

Press Run (or Ctrl + Enter) to see the result here.

Expect six rows. In the later week, the test order and the canceled order are not counted.

Step 4: Check

Before writing anything, verify by a separate route. For the week of November 23, list the included orders by hand: 6 (520), 7 (150), 8 (300 net), 9 (480) and 12 (210). The sum is 1,660 from 5 orders. The category rows should add to the same figure: Home 1,210, Garden 150 and Kitchen 300.

For the week of November 16: 300 + 420 + 280 + 300 + 200 = 1,500 from 5 orders.

Step 5: Generate the report

This program takes the query results as input, runs a gate check, then renders the table and findings. In production, the rows would come from the database instead of being typed in.

Python Render the weekly report

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The output shows net sales of 1,660, up 10.7%, with the same number of orders. Home rose by 610, while Garden fell by 270 and Kitchen by 180. The changes add to +160, which matches the change in the total.

Step 6: Write the findings

Use the fact, comparison, meaning and next step pattern.

TEXT
Net sales reached 1,660 (target 1,500), up 10.7% on last week.
Orders were unchanged at 5, so the rise came from a higher
average order value (332 against 300).
Home added 610; Garden fell 270 and Kitchen 180.
With so few orders, one large order can move these figures,
so check individual orders before changing plans.

This wording describes what changed. It does not say why customers bought more Home items, because the data does not contain that.

Step 7: Deliver and maintain

Plan the gate checks (complete week, reconciled total, no unknown categories), the delivery key (report, week, version), the recipient list and the owner. Review the report after a month: which part do readers use, and which can go?

Reading the result critically

Look again before you send it. The headline is positive, since the target was met and sales grew. But three details change how a lead might act.

First, the rise is concentrated. Home grew by 610, which is more than the whole increase of 160. Without that growth, the total would have fallen. A summary that says only "sales up 10.7%" would hide two declining categories.

Second, the sample is tiny. One Home order of 520 is almost a third of the week's net sales. Remove it and the week misses the target. That does not make the order any less real, but it shows how fragile the status label is.

Third, refunds can still arrive. The newest orders have had the least time to be refunded, so this week's net sales may fall later. If your business sees many late refunds, say that recent figures are provisional, and decide whether published weeks will be restated.

You could add one sentence for the sales lead: "The increase depends on Home, and a few large orders have a big effect; please review them before shifting follow-up effort." It is accurate and tied to the decision in the brief.

Review your own work

Score your finished version against these questions, and fix any "no".

Question Where to look
Does the page answer both questions in the brief? Step 1
Can a reader find each definition? Step 2
Is every filter applied in one place? Step 3
Was the control total produced separately? Step 4
Do words and numbers agree? Steps 5 and 6
Is there an owner and a plan for late data? Step 7

Then give the output to someone who has not seen the data. Ask them what happened and what they would do next. If they conclude that Home is a safe long-term growth area, your wording or your caveat is too weak, because two weeks cannot show that. Revise it and ask again.

Keep your first version and your revised version side by side. The differences show which habits you still need to practice, and they make a useful starting point for your next report. Write down one habit that you will check first next time.

The control total in this project is typed by hand. In a real job, take it from an independent source. A control figure calculated by the same query cannot catch errors in that query.

Extensions

  1. Add a category that exists in only one week and confirm that the changes still add up.
  2. Build a complete daily series with a calendar CTE.
  3. Move refunds to their own table with their own dates, then update the definition.
  4. Produce an escaped HTML version of the table.

Check your understanding

Quick check · 3 questions

of 3 answered You scored / 3 · perfect!

  1. 1. Why did the project compare the report total with a hand-counted figure?

    An independent figure can reveal mistakes in the query logic.
  2. 2. Net sales rose while the order count stayed the same. What does the arithmetic show?

    With equal orders, higher sales mean a higher average per order. The data says nothing about reasons.
  3. 3. Why does the report mention the number of orders in a note?

    Readers need to know how fragile the percentages are.

Summary

  • Start with a brief and written definitions.
  • Apply filters once in the query, then verify totals independently.
  • Gate publication on reconciliation and render consistent tables.
  • Make category changes add up to the total change.
  • Report what changed, state limits and plan delivery and review.

Next: Project: A KPI Dashboard

Seu progresso fica salvo neste navegador. Não precisa de conta.