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 :
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

  • D365FO user Profile Picture
    465 on at

    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
    27 Moderator on at

    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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 245 Super User 2026 Season 2

#2
Aayush Tiwari Profile Picture

Aayush Tiwari 227

#3
Subra Profile Picture

Subra 184 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans