liveBook · Manning

Average transaction value

As explained in Build Python Web Apps with Streamlit

Average transaction value is the mean sales revenue associated with each transaction over a specified scope or period.

Average transaction value (ATV) helps a dashboard show how much revenue, on average, each transaction generated. Users can compare it across products, categories, customer groups, states, and time. section 6.1.2

Calculate ATV by dividing total sales by the total number of transactions in the selected slice: total sales / sum of transactions. A transaction represents one purchase, regardless of how many items it contains. section 6.4.1

Three-row calculation

Suppose three rows contain sales of $500, $300, and $200, with 10, 5, and 8 transactions. Total sales equal $1,000, and total transactions equal 23, so ATV is $1,000 / 23 = $43.48. section 6.4.1

Use ATV carefully when building dashboard views:

  • Recalculate the ratio for each filtered group by dividing that group’s total sales by its transaction count. section 6.5.2
  • Treat ATV as a ratio rather than a component of a pie chart, because dimension-wise ATV values do not add up to 100 percent. section 6.5.2
  • Configure ATV as a dollar-valued metric and guard the calculation against a zero-sales denominator. section 6.4.2
Listing 6.7 Configuring metrics
from metric import Metric

def margin_percent(df):
  total_sales = df["Sales"].sum()
  return df["Gross margin"].sum() / total_sales if total_sales > 0 else 0

def average_transaction_value(df):
  total_sales = df["Sales"].sum()
  return total_sales / df["Transactions"].sum() if total_sales > 0 else 0

metrics = {
  "Total sales": Metric(
    title="Total sales",
    func=lambda df: df["Sales"].sum(),
    type="dollars"
  ),
  "Gross margin": Metric(
    title="Gross margin",
    func=lambda df: df["Gross margin"].sum(),
    type="dollars"
  ),
  "Margin %": Metric(
    title="Margin %",
    func=margin_percent,
    type="percent"
  ),
  "ATV": Metric(
    title="Average transaction value",
    func=average_transaction_value,
    type="dollars"
  )
}

display_metrics = ["Total sales", "Gross margin", "Margin %", "ATV"]

A compact Python configuration shows ATV as a reusable dollar metric alongside total sales, gross margin, and margin percentage. section 6.4.2

How Build Python Web Apps with Streamlit covers it

How deep it goes
Defines the formula, works through a numeric example, and implements configuration with a zero-sales guard.
Examples
Uses three sales rows totaling $1,000 and 23 transactions to produce an ATV of $43.48.
What it assumes
Assumes sales and transaction-count fields, while explaining from zero what a transaction and sales amount represent.
What you can do after
Build it from scratch by defining an ATV function and registering it as a dollar-valued dashboard metric.
How it connects
Connects sales, transactions, filtering, time trends, metric configuration, and dashboard visualization.

Also explained in

Compare how 2 books explain average transaction value →

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.