Design report datasets for business requirements
A maintainable report starts with a dataset that represents the business question independently of any layout. You first translate the reporting requirement into records, relationships, values, and filters that Business Central can process consistently.
Map requirements to dataset elements
The dataset section of a report object defines a hierarchy of data items. Each data item reads a table, and its columns expose fields, variables, labels, or expressions to layouts. Start by identifying the grain of each output row. An operational customer list usually has one row per customer. A sales document usually has a header, one or more lines, and supporting records such as company or address information.
Use these elements deliberately:
- A data item identifies the table and iteration level.
- A
columnexposes a value to every declared layout. DataItemTableViewsets sorting and fixed filters that apply whenever the report runs.RequestFilterFieldsexposes selected table fields on the request page.DataItemLinkrelates a child data item to fields in its parent.- A label supplies translatable text without hard-coded layout strings.
- A calculated column exposes a derived value after AL computes it.
The following pattern links sales headers to the current customer. The link becomes a filter on the child data item for each parent record.
dataset
{
dataitem(Customer; Customer)
{
RequestFilterFields = "No.", City, "Country/Region Code";
column(CustomerNo; "No.") { }
column(CustomerName; Name) { }
dataitem(SalesHeader; "Sales Header")
{
DataItemLinkReference = Customer;
DataItemLink = "Sell-to Customer No." = field("No.");
DataItemTableView = where("Document Type" = const(Invoice));
column(DocumentNo; "No.") { }
column(DocumentDate; "Document Date") { }
}
}
}
The parent field in field("No.") refers to the Customer data item. This relationship belongs in the dataset, not in the layout. A layout arranges values, but it doesn't create record relationships.
Distinguish operational and document hierarchies
An operational report supports review, analysis, or follow-up. Its dataset often uses a flat grain, such as one row per customer with No., Name, City, Country/Region Code, Balance (LCY), and Salesperson Code. A flat structure works well for Excel analysis and many RDL lists.
A document report represents a business document. Its dataset commonly follows a hierarchy:
- A header data item supplies document and recipient information.
- A child line data item links to the header and repeats detail rows.
- Nested supporting data items provide taxes, comments, dimensions, or other grouped information.
- Columns expose totals, labels, and formatted values needed by the document layout.
Avoid duplicating header values through unrelated root data items. The nested structure gives Word and RDL layouts the grouping context they need. It also lets the report apply child filters for each parent record.
Calculated values need an explicit evaluation point. FlowFields such as Balance (LCY) require CalcFields before AL code reads them. You can calculate a value in OnAfterGetRecord, assign it to a variable, and expose that variable as a column. Keep calculations in AL when they define business meaning. Reserve layout expressions for presentation-only work.
Inspect the dataset before layout work
A correct-looking layout can hide a flawed dataset. Validate the data contract before you spend time on typography, grouping, or pagination. In the report request page, Send to > Microsoft Excel Document (data only) exports the dataset without applying a layout. Inspect the workbook for:
- The expected row grain and parent-child sequence.
- Correct record counts after filters and links.
- Required columns, labels, and calculated values.
- Appropriate data types for totals, dates, and formatting.
- Duplicate rows caused by an incorrect hierarchy.
Use a small set of known records and vary one filter at a time. If a child data item returns unexpected records, inspect DataItemLink, DataItemTableView, and filters added in OnPreDataItem. This sequence separates data problems from layout problems and establishes a stable contract for every layout that follows.
For syntax and dataset behavior, see Report object and Report dataset.