# Build grouped reports without broken table markup Use one dataset and `{#GroupBy}` when the categories can change. Use deliberately filtered query aliases when each section has a different data-selection rule. [Build nested bundle tables from a priced quote.](#cpq-quote) #### One table per stage Select Opportunities with `Name`, `StageName`, and `Amount`. Sort by `StageName` if you want groups in stage order. This HTML wraps a complete table in the group and keeps the row loop inside its cells: ```html
| Opportunity | Amount |
|---|---|
| {#Opportunities}{Name} | {Amount:currency}{/Opportunities} |
Stage total: {SUM:Opportunities.Amount:currency}
All stages: {SUM:Opportunities.Amount:currency}
``` Inside the group, the Opportunities relationship contains that group's members. Outside it, the total sees the whole available relationship. `{RowNumber}` restarts within each group's row loop. #### A different alias is not a filter Renaming `{#QuoteLineItems}` to `{#Purchase}` does not select purchase items. `Purchase` must exist in Query Config or the supplied data. Either configure two filtered aliases, use a prepared provider, or keep the real relationship and apply conditions to its rows. A conditional display does not automatically change an aggregate over the unfiltered relationship. #### Keep table HTML valid Do not place naked loop/IF text directly between `