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)

Trial Balance SQL

(0) ShareShare
ReportReport
Posted on by

I need  to  see the balances by Account using a SQL query against our database for All Accounts.  

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Brandon Wiese Profile Picture
    17,788 on at

    This will be incredibly slow and hard on your SQL Server if you have a large number of records in your ledger.  There are faster but more complex ways to arrive at the same answer, depending on your needs.  The current balance in any account is the sum of all operating (not opening or closing) transactions in that account.

    SELECT m.[PARTITION], m.MAINACCOUNTID, SUM(a.ACCOUNTINGCURRENCYAMOUNT) AS ACCOUNTINGCURRENCYAMOUNT
      FROM GENERALJOURNALACCOUNTENTRY a
      JOIN GENERALJOURNALENTRY e  ON e.[PARTITION] = a.[PARTITION] AND e.RECID = a.GENERALJOURNALENTRY
      JOIN MAINACCOUNT m          ON m.[PARTITION] = a.[PARTITION] AND m.RECID = a.MAINACCOUNT
      JOIN FISCALCALENDARPERIOD p ON p.[PARTITION] = e.[PARTITION] AND p.RECID = e.FISCALCALENDARPERIOD
      WHERE p.[TYPE] = 1  -- 0=Opening,1=Operating,2=Closing
      GROUP BY m.[PARTITION], m.MAINACCOUNTID
      ORDER BY m.[PARTITION], m.MAINACCOUNTID
    


  • Suggested answer
    Brandon Wiese Profile Picture
    17,788 on at

    The problem with using DimensionFocusBalance, while it does have far fewer records than GeneralJournalAccountEntry records and is thus much faster, is that not all vouchers are guaranteed to be absorbed into DimensionFocusBalance.  

    When a user opens the Trial balance list page or runs the Trial balance report in AX, the Dimension set is incrementally updated to flush the DimensionFocusUnprocessedTransactions.  Without processing those unprocessed vouchers, the results will not reflect the current balance.  

    Your code does not do that processing, and certainly SQL code cannot do it either.

    SQL can achieve an accurate balance by using a union on DimensionFocusBalance and DimensionFocusUnprocessedTransactions, without having to actually absorb them into the Dimension set.  Hence, the more complex solution I alluded to.

  • Community Member Profile Picture
    on at

    Is there a way where I can select different month's out of the year...for Instance I want to look at August Trial Balance?

  • Brandon Wiese Profile Picture
    17,788 on at

    The balance for any main account at any point in time is the sum of all transactions on/before that point in time.  In other words, if you add up all transactions on/before a given date, you will have the ending balance as of that date.  Thus, add a date filter to your SQL.

  • Community Member Profile Picture
    on at

    So I would I use the AccountingDate in the SQL expression?

  • Community Member Profile Picture
    on at

    I would like to see this expression work with Accounting Date and Showing all AR Balances, would that be a specific Main Account?

  • Community Member Profile Picture
    on at

    Can I run this as a New Query in Morphx or can it be ran in SQL Management Studio?

    If Morphx, where in the query can I add this code?  Under Methods?

  • Brandon Wiese Profile Picture
    17,788 on at

    Usually when someone talks about A/R balances, they mean each customer's balance, and that's not drawn from ledger or main accounts.  You will certainly have one or more main accounts that represent the total balance of A/R trade.  But, those are 2 different things.

    In your original post, you said "all accounts" but you really weren't clear what you wanted.

    Shouldn't you get a lot more specific?

  • Community Member Profile Picture
    on at

    Yes I agree, the direction changed from All Accounts to specific accounts based on the requester since posting. I'm assuming the total balance of AR Trade...but it was requested the following accounts:

    • A/R

    • Net Revenue

    • A/P

    • COGS

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