web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

VAT Entry and Cust. Ledger Entry TotalVAT

(0) ShareShare
ReportReport
Posted on by 50

Hi,

i want to add function which sum Total VAT Amount from VAT Entry filtered by Customer (Cust. Ledger Entry). 

I struggle with filter Amount per Customer. Below is my code.

var
        CustLedgerEntry: Record "Cust. Ledger Entry";
        TotalVAT: Decimal;
        VatEntry: Record "VAT Entry";
 procedure TotalVAT()
    begin
        CustLedgerEntry.CalcFields("Remaining Amt. (LCY)", "Remaining Amount", CustLedgerEntry."Original Amt. (LCY)");
        TotalVAT := 0;
        VatEntry.Reset();
        VatEntry.SetRange("Document No.", CustLedgerEntry."Document No.");
        VatEntry.SetRange("Transaction No.", CustLedgerEntry."Transaction No.");
        if VatEntry.FindSet() then begin
                VatEntry.CalcFields("ITI VAT Base");
                TotalVAT += -VatEntry."ITI VAT Amount" - VatEntry."Unrealized Amount";
            until VatEntry.Next() = 0;
        end;
Any ideas? 
I have the same question (0)
  • Suggested answer
    Nitin Verma Profile Picture
    21,812 Moderator on at

    Hi,

    Please do the yellow mark

    var

           CustLedgerEntry: Record "Cust. Ledger Entry";

           TotalVAT: Decimal;

           VatEntry: Record "VAT Entry";

    procedure TotalVAT()

       begin

           CustLedgerEntry.reset;

           CustLedgerEntry.setrange("Customer No.",Customer."No.");

            CustLedgerEntry.findset;

            repeat

           CustLedgerEntry.CalcFields("Remaining Amt. (LCY)", "Remaining Amount", CustLedgerEntry."Original Amt. (LCY)");

           TotalVAT := 0;

           VatEntry.Reset();

           VatEntry.SetRange("Document No.", CustLedgerEntry."Document No.");

           VatEntry.SetRange("Transaction No.", CustLedgerEntry."Transaction No.");

           if VatEntry.FindSet() then begin

                   VatEntry.CalcFields("ITI VAT Base");

                   TotalVAT += -VatEntry."ITI VAT Amount" - VatEntry."Unrealized Amount";

               until VatEntry.Next() = 0;

           end;

            until         CustLedgerEntry.next = 0;

    Any ideas?

  • Tony00001 Profile Picture
    50 on at

    It doesn't work right. I get on every customer record the same result.

  • Tony00001 Profile Picture
    50 on at

    It only get last record in VAT Entry, doesnt sum.

  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at

    Hi Tony00001

    Try this code instead. You were missing the repeat while looping through the VAT entries-

    if VatEntry.FindSet() then repeat

                   VatEntry.CalcFields("ITI VAT Base");

                   TotalVAT += -VatEntry."ITI VAT Amount" - VatEntry."Unrealized Amount";

               until VatEntry.Next() = 0;

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,260 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,515 Super User 2026 Season 1

#3
AndrewThomas81 Profile Picture

AndrewThomas81 1,373

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans