liveBook · Manning

Gross margin

As explained in Build Python Web Apps with Streamlit

Gross margin is a profitability metric representing sales revenue remaining after subtracting the cost of goods sold.

Gross margin measures the sales revenue left after paying the cost of the items sold. In a dashboard, it shows the profit contribution behind sales for a selected product, period, customer group, or location. section 6.1.2 section 6.4.1

Calculate gross margin for any slice of the data by summing its gross margin values. Keep it separate from margin percentage: margin percentage divides total gross margin by total sales and expresses the result as a percentage. section 6.4.1

A three-row calculation

Suppose three rows report sales of $500, $300, and $200, with gross margins of $200, $120, and $80. Total sales are $1,000, while gross margin is $400. The corresponding margin percentage is 40%. section 6.4.1

| Date       | Product      | State |  Sales | Gross Margin | Transactions |
|------------|--------------|-------|--------|--------------|--------------|
| 2024-01-01 | Fountain Pen | CA    |    500 |          200 |           10 |
| 2024-01-01 | Notebook     | TX    |    300 |          120 |            5 |
| 2024-01-01 | Pencil       | NY    |    200 |           80 |            8 |

Use the sample rows to verify that gross margin can be aggregated across products and states before displaying a dashboard total. section 6.4.1

How Build Python Web Apps with Streamlit covers it

How deep it goes
Defines gross margin and gives its aggregation rule, while deferring broader dashboard implementation details.
Examples
Uses CSV rows, product and state dimensions, and a three-row calculation totaling $400 gross margin.
What it assumes
Assumes sales, cost, and transaction fields, while defining gross margin and related metrics from those fields.
What you can do after
Evaluate profitability by summing gross margin values for any selected slice of sales data.
How it connects
Connects gross margin with sales, cost, margin percentage, average transaction value, and dashboard filtering.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Python Web Apps with Streamlit. The section links point to the parts of the book it draws on.