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 :
Microsoft Dynamics AX (Archived)

SUM/Query

(0) ShareShare
ReportReport
Posted on by

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

  • Suggested answer
    Community Member Profile Picture
    on at

    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.

  • Suggested answer
    reachnaidu Profile Picture
    890 on at

    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

  • Verified answer
    Martin Dráb Profile Picture
    240,744 Most Valuable Professional on at

    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.

  • Community Member Profile Picture
    on at

    Thanks Martin I Used your code and it is working

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans