Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

SUM/Query

Posted on by Microsoft Employee

Dear Experts

I have different columns in grid for Amount  I want total at bottom of grid  and grid is bound to custom table (ARM_INVOICEDETAIL) and their is no query in AOT  how can i take sum of each column.

Thanks

Afridi

I found Below query on Martin Page

// Copy the query
Query query = new Query(SalesLine_ds.queryRun().query());

QueryBuildDataSource qbds = query.dataSourceTable(tableNum(SalesLine));
QueryRun qr;
Salesline summedTrans;

// Sum LineAmountMst
qbds.addSelectionField(fieldNum(SalesLine, LineAmount), SelectionField::Sum);
qr = new QueryRun(query);
// Run the query
qr.next();

// Get the data
summedTrans = qr.get(tableNum(SalesLine));
// Set the new sum to the control
RealEdit.realValue(summedTrans.LineAmount);
txtitemid.text("1000");

 

 

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SUM/Query

    Thanks Martin I Used your code and it is working

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,149 Most Valuable Professional on at
    RE: SUM/Query

    Can you explain what kind of problem you have with the code you've posted?

    Also, the code uses a query from the form, not some separate query in AOT. If your form has a datasource, it also has a query.

  • Suggested answer
    reachnaidu Profile Picture
    reachnaidu 890 on at
    RE: SUM/Query

    In the table ARM_INVOICEDETAIL , create a new display method Sum() and add the fields which you need.

    like this.Field1 + this.Field2 .. etc and use the display field at the end of the row of the grid

    If you want to sum only one field out of the table, use the same procedure above and write a simple query

    Select Sum(LineAmount) from SalesLine

    where Salesline.SalesId = this.SalesID

    and return SalesLine.LineAmount ..This should give you the whole value

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SUM/Query

    Hi

    One way is to create a query object in AOT, with the desired sum fields. use that query in your code to get the result.

    for eg: for SalesLine, in the query >> Datasources >> SalesLine >> fields >> New Sum.

    select the field as LineAmount.. you must have the Dynamic property to "No" before you do this.

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