WhoDB PlatformDocs

Find return-rate problems by product cohort

Identify products with unusually high return rates while keeping the denominator and observation window explicit. This recipe produces a product-quality review list rather than a list ranked only by return volume.

Before you begin#

You need a project where you can create transforms and datasets, plus an available Python script runtime. The sample contains only synthetic records. Start with the complete CSV, not a limited preview of a larger business dataset.

Follow Run a use-case recipe for the shared input, destination, and app steps.

Sample input#

Download the CSV, or copy it into Transforms → Library → Seed → Paste CSV.

Csv

sku,sold_units,returned_units,cohort
RET-1,100,12,2026-09-closed
RET-2,200,4,2026-09-closed
RET-3,0,0,2026-09-closed
RET-4,10,12,2026-09-closed

Build it in WhoDB#

  1. Prepare one row per SKU and closed sales cohort. returned_units must refer to returns from those same sales, not returns received in an unrelated month.
  2. Create Return rate review, paste the sample into Seed, and connect Script → Python with the code below.
  3. Declare the output columns and preview every SKU. The example uses a review threshold of 8%; change it only after your team agrees on the definition.
  4. Filter return_status != ok and save to return_rate_review. Keep invalid-cohort rows visible rather than dropping them.
  5. Use an app table for the product owner to inspect cohort, sold/returned units, rate, and status. Add a separate reason-level analysis only when return reason data exists.

Script and output columns#

In Script → Output columns, add these names exactly, in this order:

Text

sku, sold_units, returned_units, cohort, return_rate_pct, return_status

Paste this code into Script. Select Python and leave Dependencies empty; it uses the Python standard library.

Python

def main(input):
    output = []
    for row in input:
        sold, returned = int(row["sold_units"]), int(row["returned_units"])
        invalid = sold < 0 or returned < 0 or returned > sold
        rate = round(returned / sold * 100, 2) if sold > 0 and not invalid else ""
        status = ("invalid_cohort" if invalid else "no_sales" if sold == 0
            else "high_returns" if rate >= 8 else "ok")
        output.append(dict(row, return_rate_pct=rate, return_status=status))
    return output

Download the script · Expected fixture output. The expected output is computed from this CSV and script; it is not a screenshot of a hosted run.

Check the result#

RET-1 is high_returns at 12.0%; RET-2 is ok at 2.0%; RET-3 is no_sales with no rate; RET-4 is invalid_cohort because returns exceed the defined sales cohort. A zero denominator must never become a zero-percent success.

Find the controls#

These screenshots show the current pipeline configuration controls used in this recipe. They come from the manual’s synthetic demonstration workspace; they do not show this use case already executed.

Script: select Python, declare output columns, and paste the calculation.Script: select Python, declare output columns, and paste the calculation.

Script: select Python, declare output columns, and paste the calculation.Script: select Python, declare output columns, and paste the calculation.

Put it to work#

Wait for a sufficient return window before comparing cohorts. Separate cancellations, exchanges, and refunds according to your business definition. Track the fraction of high-rate products investigated and the reason confirmed by the investigator; this recipe does not infer product defects from a rate alone.

For output mapping and rerun behavior, follow Write pipeline outputs. For a team-facing screen, follow Create an app and Connect state and data.

Was this page helpful?