A revenue query can return three plausible numbers for the same company and reporting period: consolidated revenue, cloud segment revenue, and hardware segment revenue. If the query groups by concept and date alone, whichever row arrives last can overwrite the others. Summing every row is worse: segment totals may already be part of the consolidated figure.

The dates and units can match perfectly while the facts describe different scopes. Keep the dimensions attached to the fact until the query has chosen the intended scope.

A small example

These are fictional facts, in millions of dollars, for the same annual period:

facts = [ {"concept": "Revenue", "period": "FY2025", "unit": "USDm", "dimensions": {}, "value": 1000}, {"concept": "Revenue", "period": "FY2025", "unit": "USDm", "dimensions": {"Segment": "Cloud"}, "value": 600}, {"concept": "Revenue", "period": "FY2025", "unit": "USDm", "dimensions": {"Segment": "Hardware"}, "value": 400}, ] 

A dictionary keyed only by (concept, period, unit) retains one of these values. A sum returns 2,000, although consolidated revenue is 1,000 in this example. The segment figures add to the consolidated value only because the example was constructed that way; real segment disclosures can include eliminations or reconciling items.

For filing-level XBRL, a fact's context identifies the entity and period and may include dimensional information. The XBRL specification describes contexts and dimensions in the dimensions specification. The reported concept and value alone are insufficient to distinguish those contexts.

Preserve the scope in the key

For this toy input, turn dimensions into an order-independent tuple before grouping:

def scope_key(fact): dimensions = tuple(sorted(fact["dimensions"].items())) return (fact["concept"], fact["period"], fact["unit"], dimensions) by_scope = {scope_key(f): f["value"] for f in facts} assert len(by_scope) == 3 assert by_scope[("Revenue", "FY2025", "USDm", ())] == 1000 assert by_scope[("Revenue", "FY2025", "USDm", (("Segment", "Cloud"),))] == 600 

This example assumes a single entity, filing, and observation per scope. Production keys also need the entity identifier, actual start and end dates or instant, taxonomy namespace, unit, and filing provenance. Keep the original context identifier and accession number alongside the parsed dimensions so a reviewer can return to the source. Duplicate facts can still share a semantic key: retain their source locations and check for conflicting values instead of silently overwriting them.

An empty dimension map in this example denotes the consolidated value. In a real filing, an empty map alone does not prove consolidated scope. Entity identifiers, context definitions, default dimension members and the financial statement presentation all need attention. Typed dimensions and namespace-qualified names also need canonical handling; a simple string dictionary is only a teaching model.

Check the source before using company facts

The SEC's EDGAR API documentation describes its XBRL aggregation APIs and their scope. Company facts are useful for standardized entity-wide concepts, but a missing segment row in that response does not establish that the filing lacks segment data. Inspect the filing's inline XBRL and the segment note when the question requires a particular business or geography.

When extracting the filing, compare the context for a candidate against the table containing it. Check whether a segment is a reportable segment, a geography, or a product category; two axes can appear in the same context. Preserve every relevant axis rather than flattening the first member into a generic segment column.

Decide what a comparison means

A year-over-year chart for Cloud needs the same economic scope in both periods. A renamed or reorganized segment may require the company's recast comparative figures, and a member name match alone cannot establish comparability. Record which filing supplied each value, read the segment note for changes, and leave a break in the series when the scopes cannot be reconciled.

For a consolidated chart, select the context supported by the consolidated statement. For a segment chart, select the relevant dimensional context and show any reconciliation separately. This avoids counting consolidated revenue again when segment data is added to the pipeline.