web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Group by & Order by count(RecId)

(0) ShareShare
ReportReport
Posted on by

CustTable custTable;
while select count(RecId), CustGroup from custTable
group by CustGroup
order by custTable.RecId desc
{
info(strFmt("%2 - %1", custTable.RecId, custTable.CustGroup));
}

Hello, I've encountered interesting case in AX 2012. Basically what I am trying to do is to sort my data by the amount that count(RecId) returns when it is grouped by CustGroup. Well, "order by custTable.count(RecId) or any other variation of that arises syntax error. Do you have any idea, what to do with this? 

I was suggested to use View, but even with View, I couldn't find the solution which lets me order by the expression of aggregated function (count in this case).

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    Hi!

    I try use a view and it work

    ustTable custTable;
        CustTestView  CustTestView;
        
        while select count(RecId), CustGroup from custTable
            group by CustGroup
            order by custTable.RecId desc
            
        {
            info(strFmt("%2 - %1", custTable.RecId, custTable.CustGroup));
        }
        
        info('View');
        
        while select CustTestView
            order by CountOfRecId desc
        {
                info(strFmt("%2 - %1", CustTestView.CountOfRecId, CustTestView.CustGroup));
        }    


    8321.Test.jpg

  • Community Member Profile Picture
    on at

    That settles everything. I had been trying to put the whole logic either in select statement or in View, together they work perfectly. Thanks for your effort!

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans