How to: Calculate purchase order total value

Posted on Updated on

Today I will post a piece of code used to get the purchase order total value.
This value can also be found on Totals form, which can be accessed through:
Accounts payable/Common/Purchase orders/All purchase orders/Tab – Purchase Order/Group – View/Totals

2014-04-17 11_07_15-‪Totals‬ (‎‪2‬ - ‎‪usmf‬)‎‪ - ‎‪‪‪Purchase order‬_ ‎‪000023‬‬, ‎‪‪Fabrikam Suppl

How to get it through X++, in this example I have created a new Job.

static void _GetPurchTotalAmount(Args _args)
{
    PurchTotals purchTotals;
    PurchTable  purchTable  = PurchTable::find('000023');
    DiscAmount  discAmount;
    ;

    purchTotals = PurchTotals::newPurchTable(purchTable);
    purchTotals.calc();
    discAmount = purchTotals.purchTotalAmount();

    setPrefix('Purchase Order');
    info(strFmt('%1 - Total Value: %2', purchTable.PurchId, discAmount));
}

Result:

2014-04-17 12_30_50-‪Infolog‬ (‎‪1‬)‎

11 thoughts on “How to: Calculate purchase order total value

    caleb kiran said:
    May 6, 2014 at 7:22 am

    how to get PO sub total value, can you tell me…

      Christian Fleishmann Silva responded:
      May 6, 2014 at 10:26 am

      Good day Celeb,

      Use “purchTotals.purchBalance()” instead of “purchTotals.purchTotalAmount()”.

      Regards,
      Christian Silva

    […] Celeb Kiran has asked me on my post How to: Calculate purchase order total value how get the Subtotal Amount instead of Total Amount. Since one man’s doubt is another […]

    Felina said:
    August 11, 2015 at 1:35 am

    I would like the Net Total and the Total Amount to be included in the “Export to Microsoft Excel” add-in under Procurement and Sourcing/Common/Purchase orders/All purchase orders or have it under Menu Items by creating SSRS report. I am stuck with trying to create SSRS report for this.

    Saiful Akrom said:
    April 27, 2017 at 1:11 am

    Hello Christian,
    Thank you, it’s very usefull for me…

    Best Regards,
    Saiful Akrom

    Renee said:
    July 19, 2017 at 4:22 pm

    This is almost what I was looking for…. Do you know how I can calculate the purchase order total value by using SQL?

    Ak said:
    January 22, 2019 at 5:25 am

    Sir, how to get Sales Tax value, can you tell me…

Leave a comment