SELECT queries over reporting.*. SQL uses
the same relations as Power BI, but each query chooses its own grain, joins, filters, and result.
Read Relationships and data model before combining repeating detail.
Use this process
For each question:- Define what one result row should represent.
- Choose the relation with that grain.
- Join ownership through
entity_idorcomponent_id. - Traverse explicit relationship views when the question crosses independent objects.
- Use
EXISTSfor detail that only filters the result. - Pre-aggregate detail before combining measures from different grains.
- Validate codes, roles, currency, units, dates, nulls, and known records.
shipments or one_off_quotes by habit. Begin with the relation that matches the
answer.
Choose the starting grain
Use a wide convenience view only when the report intentionally uses one subtype and its columns.
Example 1: Inventory current entities
This query starts frombusiness_entities because one result row summarizes one entity type:
entity_type keeps their meaning explicit.
Add subtype business numbers only when needed:
Example 2: Analyze charge lines
This query starts fromentity_charges because the result measures charges, not entities:
FRT is illustrative. Inspect your organization’s observed codes before creating a recurring
query.
Example 3: Traverse explicit relationships
This query resolves both endpoints throughentity_identities. It keeps the observer separate:
Filter entities without multiplying them
Use oneEXISTS block for each repeating relation that only determines eligibility:
Pre-aggregate detail measures
If a result needs both entity and detail measures, reduce the detail to one row perentity_id
before joining:
Inspect codes before filtering
CargoWise roles and codes can differ by organization:Validate the result
Before sharing an answer, check:- the result still has the intended grain
- every join uses a documented key
- entity relationships come from explicit edges
- codes and roles mean what the business question expects
- currencies are not mixed
- normalized units are populated for measured rows
- local dates and UTC dates are not mixed without a rule
- null and unsupported values remain visible
- a few known CargoWise records produce the expected result