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

The highest version Number

(1) ShareShare
ReportReport
Posted on by 8
Hi All,
 
I am trying to calculate the sum of the line Amount from the Purchase line archives table but, I need just the highest /version No./ foreach line and with the same /Job No./,
I tried this but it's not working.
Can anyone Help please?
Thank you.
I have the same question (0)
  • Yael Suarez Profile Picture
    131 on at
    Hello, how have you tried to try with

    VariableRecord.SetCurrentKey(Version No);
    VariableRecord.SetAscending(Version No, true);

    substituting the version setrange into your line of code
    I hope this can help you
  • Suggested answer
    YUN ZHU Profile Picture
    100,212 Super User 2026 Season 1 on at
  • SM-29041600-0 Profile Picture
    8 on at
    Hi All,
    Thank you very much for your response!
    I tried to work with the query, it brings the last version, but I need to sum the line_amount for the records with the same "Job No."

    This is my query:
    query 50100 "Purchase Line Archive ZWT"
    {
        QueryType = Normal;
        OrderBy =descending(Version_No_);
        elements
        {
            dataitem(Purchase_Header_Archive; "Purchase Header Archive")
            {
                column(No_; "No.")
                {
                }
                column(Document_Type; "Document Type")
                {
                }
     
                dataitem(Purchase_Line_Archive; "Purchase Line Archive")
                {
                    DataItemLink = "Document No." = Purchase_Header_Archive."No.", "Document Type" = Purchase_Header_Archive."Document Type";
                    SqlJoinType = InnerJoin;
                    column(Document_No_; "Document No.")
                    {
                    }
                    column(Line_No_; "Line No.")
                    {
                    }
                    column(Job_No_; "Job No.")
                    {
                       
                    }
                    column(Version_No_; "Version No.")
                    {
                        Method = Max;
                    }
                    column(Line_Amount; "Line Amount")
                    {
                    }
                }
            }
        }
     
        trigger OnBeforeOpen()
        begin
     
        end;
    }

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,012 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 986 Super User 2026 Season 1

#3
Teagen Boll Profile Picture

Teagen Boll 659 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans