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)

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 39

#2
Michel ROY Profile Picture

Michel ROY 14

#3
imran ul haq Profile Picture

imran ul haq 8

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans