Dynamics 365 Business Central: How to calculate the total (sum) of a column in a table (Four ways)
The post explains four methods to calculate column totals in Business Central: using AL loops (for, foreach, while, repeat-until), the Record.CalcSums method, Query objects with aggregation, and FlowFields. Each approach has different use cases and performance characteristics for developers calculating sums of data.

post Dynamics 365 Lab
"The CalcSums function is used to calculate a total for a specific field, based on the filters of the dataset."
Key points
- AL loops such as repeat-until work in every situation but are not the most efficient way to total a column
- CalcSums totals a field using current filters, is fastest with matching SumIndexFields keys, and does not accept FlowFields
- Query objects with the Sum method, optionally grouped by Year, are recommended for frequent calculations at the cost of an extra object
- FlowFields defined with CalcFormula show totals on pages without extra code but need a new field in a table
Quotes
- “The CalcSums function is used to calculate a total for a specific field, based on the filters of the dataset.” (Explains the core purpose and mechanism of the CalcSums method, the most efficient approach for total calculations)
- “This is very useful for displaying totals on a page, as there is no need to add additional logic, just the properties.” (Highlights the key advantage of FlowFields: automatic calculation without code, reducing development effort)
- “If frequent calculations are required, this method is recommended.” (Identifies when Query objects should be used, guiding developers to choose the right approach for their scenario)
AL objects mentioned
As named in the post. A name that matches one object page by exact type and name links to it; the others stay as named.
- table 21 “Cust. Ledger Entry”
- table 18 “Customer”
- query “CustLedgerEntriesGroupByYear”
- other “pageextension CustomerLedgerEntriesExt”
- other “pageextension CustomerListExt”
- other “tableextension CustomerExt”
Not found in BC28-30: query “CustLedgerEntriesGroupByYear”.
Possibly related
No source states these links: they share an object, a model read them, or a person found the same subject.
- Business Central 2026 release wave 2 (BC29): AL developers can turn indexes on/off in AL code — possibly related: both name Table 21 “Cust. Ledger Entry”
- Business Central Queries: Simplifying Complex Data — possibly related: both name Table 21 “Cust. Ledger Entry”
- Creating Data Driven Text with AI in Business Central — possibly related: both name Table 21 “Cust. Ledger Entry”
- Dynamics 365 Business Central: Quickly get next Sequence/Entry Number (without using FindLast -> Entry No. + 1) — possibly related: both name Table 21 “Cust. Ledger Entry”
Heads up
- warning: “But please note that this method does not support Flowfield.”
Context
- Features: record loops, CalcSums method, Query aggregation, FlowFields, Sum calculations, Date grouping in queries, SumIndexFields
- Versions: 2025 wave 1
Source: Dynamics 365 Lab - Yun Zhu, community blog. Summary, key points and quotes are derived (CONTENT-NOTICE.md); read the original for the full text.