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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

How to use aggregation(count) in view?

(0) ShareShare
ReportReport
Posted on by 465

Hi,

I created  a view with table1, table1 contains these fields:

Table1RecId-- aggregation(Min)
JournalParmId -- i added this to the GroupBy node
JournalType

I also have range with Posted =1

This resulted in this query

SELECT        MIN(RECID) AS TABLE1RECID, JOURNALPARMID, JOURNALTYPE, DATAAREAID, PARTITION, 1010 AS RECID
FROM            dbo.TABLE1 AS T1
WHERE        (POSTED = 1)
GROUP BY JOURNALPARMID, JOURNALTYPE, DATAAREAID, PARTITION

However, i want to use count(*) with this condition having count(*) <2, how can i amend the view to get this result?

SELECT        MIN(RECID) AS TABLE1RECID, JOURNALPARMID, JOURNALTYPE, count(*), DATAAREAID, PARTITION, 1010 AS RECID
FROM            dbo.TABLE1 AS T1
WHERE        (POSTED = 1)
GROUP BY JOURNALPARMID, JOURNALTYPE, DATAAREAID, PARTITION
having count(*)<2

I have the same question (0)
  • D365FO user Profile Picture
    465 on at
    RE: How to use aggregation(count) in view?

    I added Table1RecId again in the view and called it Table1RecIdCount and used for it Aggregation=count

    and to put the having condition, i had to use the view in another view to put the condition Table1RecIdCount <2  -- but now it's in "where" condition instead of "having", how can i make it having?

  • Suggested answer
    nunomaia Profile Picture
    23 Moderator on at
    RE: How to use aggregation(count) in view?

    This is an old article ( AX ) but it is still valid,

    check this learn.microsoft.com/.../walkthrough-creating-an-aot-query-that-has-group-by-and-having-nodes

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,004

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 857 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 548 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans