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

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,857 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,047 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 959 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans