Skip to main content

Notifications

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

Filter Record

Posted on by 768

Hello Experts

I have created "Test" a table with 4 fields 

ID        JobNo           ProductID             QtyRequired

This table contain the following data 

ID        JobNo           ProductID             QtyRequired

1          1                    4                            2

2          1                    4                            3

3          1                    3                            7

4          3                    2                            2

Now i have only JobNo 1 to filter record in a table now i want to calculate  the QtyRequired  where ProductID = ProductID;

EG: 

var 

QtyRequiredSum : Integer;

QtyReqiredSum += Test.QtyRequired; // but only calculate those qtyRequied where producId = productID like for the first two record.

Thanks .

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
    RE: Filter Record

    Looks like you want to group the qty required by Product ID, if so loop the original table and add the records in a temporary table and the logic should be if you find the product id in the temporary table update qty required if not insert the record.

  • Suggested answer
    RE: Filter Record

    // Warning - un-tested code ahead :-)

    QtyRequiredSum = 0;

    Test.SETRANGE(JobNo, 1);

    IF Test.FINDFIRST() THEN BEGIN

        Test2.SETRANGE(JobNo, Test.JobNo);

        Test2.SETRANGE(ProductID, Test.ProductID);

        Test2.CALCSUMS(QtyRequired);

        QtyRequiredSum := Test2.QtyRequired;

    END;  

    Note: This assumes you only want the result for the first row (combination of JobNos and ProductIDs) - i assume this because you only have one QtyRequiredSum...

    If you need all you should create a loop and make logic to so you don't calculate already calculated combinations of JobNos/ProductIDs…

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans