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
    99,456 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!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,711 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 998 Super User 2026 Season 1

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 635 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans