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)

While Select statement with sum and group by

(0) ShareShare
ReportReport
Posted on by 700

Hi,

I have a statement that does not work as expected:

changecompany( "SAM" )
    {
        while select sum( DebitMST ), sum ( CreditMST ),  TransDate, AccountNum, PeriodCode
        from ledgerBalancesDim
        group by ledgerBalancesDim.TransDate

        where ledgerBalancesDim.AccountNum == "777777"  &&           
        ledgerBalancesDim.PeriodCode == PeriodCode::Regular &&
        ( ledgerBalancesDim.TransDate >= mkdate( 01,01,2014 ) && ledgerBalancesDim.TransDate <= mkdate( 31,12,2014 ))
        {
            Do my thing
        }
}


 I need to go through records in the view "LedgerBalancesDim" that grouped by date and get the sum of "DebitMST" and "CreditMST".

But the result set limits only to the requirement:

 ledgerBalancesDim.TransDate >= mkdate( 01,01,2014 ) && ledgerBalancesDim.TransDate <= mkdate( 31,12,2014 )

and not to the AccountNum  and PeriodCode.


What is wrong with the query?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    startax Profile Picture
    1,845 on at

    Hi Pam,

    As suggested by @Sukrut  use AccountNum, and PeriodCode also in your Group by.

  • OrangeRocks Profile Picture
    700 on at

    Hi Sukrut and Dinkar, thank you, it worked.

    However this behavior seems strange, because I needed to group my records after TransDate only. Can you point me to the information how AX tackles this "group by" command?

  • Suggested answer
    Chaitanya Golla Profile Picture
    17,225 on at

    Hi,

    Please refer below links:

    Aggregate Functions: Differences Between X++ and SQL [AX 2012]

    msdn.microsoft.com/.../aa677419.aspx

    Select Statement Examples [AX 2012]

    msdn.microsoft.com/.../aa848113.aspx

  • Suggested answer
    Code Work Profile Picture
    15 on at

    You can try this way in your while select loop

    d365code.blogspot.com/.../return-sum-of-any-table-field-using-x.html

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