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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Reporting: How to get grand total of a multiplication

(0) ShareShare
ReportReport
Posted on by 5

Hi everyone,

I'm still struggling with C SIDE language.

I need to calculate the total stock value of the item table and already got the total stock for each product from the item ledger entry.

Now I need the grand total of all products, how I can sum all totals from each product to get the grand total?

 This is my code.

//>>  calculate total stock quantity per item no.
CLEAR(TotalStockQty);
ItemLedgerEntry.SETFILTER("Item No.",Item."No.");
ItemLedgerEntry.CALCSUMS(Quantity);
TotalStockQty:= ItemLedgerEntry.Quantity;
// <<  calculate total stock quantity per item no.

// now sum (TotalStockQty * ItemUnitCost."Unit Cost")

CLEAR(i);
CLEAR(TotalStockValue);
ItemUnitCost.SETRANGE("No.",Item."No.");
IF ItemUnitCost.FINDSET THEN BEGIN
REPEAT
TotalStockValue += (TotalStockQty * ItemUnitCost."Unit Cost");
UNTIL ItemUnitCost.NEXT =0;
END

Thanks for any advice.

I have the same question (0)
  • Suggested answer
    YUN ZHU Profile Picture
    95,599 Super User 2025 Season 2 on at

    Hi, try this?

                    begin
                        CLEAR(TotalStockValue);
                        Item.Reset();
                        if Item.FindSet() then
                            repeat
                                //>>  calculate total stock quantity per item no.
                                CLEAR(TotalStockQty);
                                ItemLedgerEntry.Reset();
                                ItemLedgerEntry.SETFILTER("Item No.", Item."No.");
                                ItemLedgerEntry.CALCSUMS(Quantity);
                                TotalStockQty := ItemLedgerEntry.Quantity;
                                // <<  calculate total stock quantity per item no.
    
                                // now sum (TotalStockQty * ItemUnitCost."Unit Cost")
    
                                TotalStockValue  = (TotalStockQty * Item."Unit Cost");
                            until Item.Next() = 0;
                    end;

    Hope this will help.

    Thank.

    ZHU

  • Mr. W Profile Picture
    5 on at

    Thanks, I tried this code, it works for grand total but then the current value for each product will be showed as 0 in my report.

    I guess it has something to do with the following reset statement "ItemLedgerEntry.Reset".

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

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 2,785

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,007 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 948 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans