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

Notifications

Announcements

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
    96,039 Super User 2025 Season 2 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

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,585

#2
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 780 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 712 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans