Skip to main content

Notifications

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.

  • Mr. W Profile Picture
    5 on at
    RE: Reporting: How to get grand total of a multiplication

    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".

  • Suggested answer
    YUN ZHU Profile Picture
    81,534 Super User 2025 Season 1 on at
    RE: Reporting: How to get grand total of a multiplication

    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

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,161 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,942 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans