A quarterly cash-flow chart can look complete even when the input filter quietly discarded half the candidate pairs. The calculated bars may all be correct, while the missing bars conceal a change in the population being analyzed.
Consider a synthetic filing dataset with three companies. Each has an annual cash-flow value and a nine-month value. For one company the nine-month period starts a month late. If a pipeline filters out that pair before subtraction, its valid results contain no trace of the rejection.
This follows the period-boundary check in A One-Month Gap Can Turn a Derived Quarter Into a Fiction. Here the focus is the output contract: retain a record for every attempted pair, including failures.
Keep the rejected row
The following example uses synthetic values in millions of dollars. Both inputs for a company use the same unit and accounting concept. start and end are inclusive dates, and the annual period end is supplied by the caller. The example is deliberately small enough to run with Python's standard library.
from datetime import date from decimal import Decimal pairs = [ {"entity": "A", "start_annual": "2025-01-01", "end_annual": "2025-12-31", "start_9m": "2025-01-01", "end_9m": "2025-09-30", "annual": "120", "nine_month": "80"}, {"entity": "B", "start_annual": "2025-01-01", "end_annual": "2025-12-31", "start_9m": "2025-02-01", "end_9m": "2025-09-30", "annual": "90", "nine_month": "60"}, {"entity": "C", "start_annual": "2025-01-01", "end_annual": "2025-12-31", "start_9m": "2025-01-01", "end_9m": "2025-09-30", "annual": "50", "nine_month": "35"}, ] def derive(row): start_a = date.fromisoformat(row["start_annual"]) end_a = date.fromisoformat(row["end_annual"]) start_n = date.fromisoformat(row["start_9m"]) end_n = date.fromisoformat(row["end_9m"]) result = {"entity": row["entity"], "q4": None, "reason": None} if start_a != start_n: result["reason"] = "start_mismatch" elif not start_a <= end_n < end_a: result["reason"] = "invalid_period_order" else: result["q4"] = Decimal(row["annual"]) - Decimal(row["nine_month"]) return result results = [derive(row) for row in pairs] for result in results: print(result) The valid values are 40 and 15. Company B produces q4: None with reason: start_mismatch. The difference 90 minus 60 is arithmetically valid, but it includes January as well as the final quarter. A null result preserves that distinction; zero would imply a measured quarter with no cash flow.
This sample assumes the caller already identified the intended annual and nine-month periods. Equal start dates and a valid order do not establish that the earlier period ends at the intended third-quarter boundary. Real fiscal calendars can use 52 or 53 weeks, so compare the end date against the issuer's actual fiscal calendar instead of hard-coding September 30. Also check entity, concept, unit and scope before subtracting.
Count attempts, not only successes
A useful run summary uses the original candidate count as its denominator:
from collections import Counter reasons = Counter(r["reason"] for r in results if r["reason"] is not None) valid = sum(r["q4"] is not None for r in results) attempted = len(results) print(f"derived={valid} attempted={attempted} rejected={attempted - valid}") print(dict(reasons)) The output is derived=2 attempted=3 rejected=1, followed by {'start_mismatch': 1}. Record the date, source accession identifiers and concept alongside each candidate in production. A reviewer can then inspect the rejected source pair without reconstructing the ingestion run.
The denominator needs a definition. This example counts pairs presented to derive; it does not count companies for which the pipeline failed to find either input. Track those missing inputs separately, starting from an explicit expected entity and period universe. Otherwise a 100% success rate can mean that only the easiest pairs reached the function.
Store the decision with the value
A derived record can carry status, reason, source accessions and a derivation field such as annual_minus_9m. Keep the inputs and decision even if a later filing changes one of the values. A subsequent run can then produce a new version instead of overwriting the evidence behind the earlier chart.
A date check alone cannot establish comparability across amendments or reclassifications. Compare the accounting basis and filing history before treating the subtraction as a reported quarter. A later comparative filing can change the nine-month figure; that change may be absorbed into an annual-minus-nine-month result. Mark the result as derived and make both accessions available to the consumer.
For an ingestion job, alert on changes in rejection counts and missing-input counts by issuer and period. A count is a prompt to inspect the underlying rows, not proof of a bad filing. A fiscal-year change, an incomplete feed or a parser regression can each produce a gap, and the appropriate fix depends on which one occurred.
