Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

Reports Building

Posted on by 195

Dear Experts:

How to make a cumulated variable in cal code appears on the layout?

When I put this variable in a textbox in the layout, it gives me a weird number.

This is my small code:

"
IF ItemRec.GET("Trans. Sales Entry"."Item No.") THEN BEGIN
UnitCost:=ItemRec."Unit Cost";
TotCost:=TotCost-"Trans. Sales Entry".Quantity*UnitCost;
END

"  

So how to make Totcost variable appears on the layout when i run the report?


Best Regards

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 73,696 Super User 2024 Season 2 on at
    RE: Reports Building

    Hi, It's not clear to me where you put this code.
    But generally you can use the following method to cumulate.

            ItemRec.Reset();
            ItemRec.SetRange("No.", "Trans. Sales Entry"."Item No.");
            if ItemRec.FindSet() then
                repeat
                    TotCost  = ItemRec."Unit Cost";
                until ItemRec.Next() = 0;

    Hope this can give you some hints.

    Thanks.

    ZHU

  • Ts. Kit Wong Profile Picture
    Ts. Kit Wong 60 on at
    RE: Reports Building

    Hi, I think you should at least show us the screenshot about your Report Dateset Designer and where you allocate your variable code. And what is the objective for the TotCost.

    TotCost for single item or the whole inventory?

    If for single item, you need to initialize your variable Totcost := 0; when next item.

    On the report layout, you may try use LAST(Fields!Totcost.Value)

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans