{"title":"FieldRef.CalcSum() Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/fieldref/fieldref-calcsum-method/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/fieldref/fieldref-calcsum-method, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/fieldref/fieldref-calcsum-method","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Calculates the total of all values of a SumIndexField in a table.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":2,"title":"Syntax","slug":"syntax","at":126,"chars":49},{"level":2,"title":"Parameters","slug":"parameters","at":175,"chars":97},{"level":2,"title":"Return Value","slug":"return-value","at":272,"chars":238},{"level":2,"title":"Remarks","slug":"remarks","at":510,"chars":1618},{"level":2,"title":"Example","slug":"example","at":2128,"chars":1082},{"level":2,"title":"Related information","slug":"related-information","at":3210,"chars":252}],"text":"> Version: _Available or changed with runtime version 1.0._\nCalculates the total of all values of a SumIndexField in a table.\n## Syntax\n```al\n[Ok := ]  FieldRef.CalcSum()\n```\n## Parameters\nFieldRef\nType: fieldref-data-type\nAn instance of the fieldref-data-type data type.\n## Return Value\n*[Optional] Ok*\nType: ../boolean/boolean-data-type\ntrue if the operation was successful; otherwise false. If you omit this optional return value and the operation does not execute successfully, a runtime error will occur.\n## Remarks\nThis method is like the ../record/record-calcsums-method method. This method operates only on records that meet the conditions of any filters associated with the record.\nIf possible, the CalcSum method uses SumIndexField Technology \\(SIFT\\). SIFT is used only if the following conditions are true:\n The Dynamics 365 key contains the fields that are used in the filters that are defined for the FlowField.\n The SumIndexFields on the Dynamics 365 key contain the field to which the FieldRef parameter refers.\n The ../../properties/devenv-maintainsiftindex-property is set to true.\n> NOTE\n> By default this property is set to true for all keys.\nFor Dynamics 365 Business Central, CalcSum execution is decoupled from Dynamics 365 SIFT index definitions. This means that if any of the conditions for using SIFT indexes are not true, then Dynamics 365 traverses all records in the base table to perform the calculation instead of using SIFT. This can reduce the number of required SIFT indexes, which can improve performance. In earlier versions of Dynamics 365, if the conditions for using SIFT indexes were not true and the MaintainSIFTIndex property was enabled, then you received an error when you called the CalcSum method. This provided a degree of protection in earlier versions against accidentally requesting a sorting for which no index existed. In Dynamics 365 Business Central, an index is not required to support a certain sorting, but sorting without an index could lead to bad performance if a search returns a large result set, which would then have to be sorted before the first row is returned.\n## Example\nThis example sets a RecordRef variable to refer to table 21, the Cust. Ledger Entry table. Next, it creates a reference to field 18, the Sales \\(LCY\\) field, in the Cust. Ledger Entry table and assigns the field reference to a FieldRef variable. The Sales \\(LCY\\) field is a decimal field and is one of the SumIndexFields on a Dynamics 365 key in the Cust. Ledger Entry table. The code displays the original Value of the FieldRef variable, then calls the CalcSum method and displays the calculated value of the field.\n```al\nvar\n    MyFieldRef: FieldRef;\n    MyRecRef: RecordRef;\nbegin\n    MyRecRef.Open(21);\n    MyFieldRef := MyRecRef.Field(18);\n    Message('Before CalcSum, Sales (LCY) is %1.', MyFieldRef.Value);\n    MyFieldRef.CalcSum;\n    Message('After CalcSum, Sales (LCY) is %1.', MyFieldRef.Value);\nend;\n```\nOn a computer that has the regional format set to English \\(United States\\), the first message window displays the following:\nBefore CalcSum, Sales \\(LCY\\) is 0.\nThe second message window displays the following:\nAfter CalcSum, Sales \\(LCY\\) is 55,162.67.\n## Related information\nfieldref-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>\n../record/record-calcsums-method\n../../../administration/optimize-sql-al-database-methods-and-performance-on-server"}