Skip to main content

Notifications

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

  • Suggested answer
    nunomaia Profile Picture
    nunomaia 9 Super User 2024 Season 1 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

  • D365FO user Profile Picture
    D365FO user 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?

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,979 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,848 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans