Skip to main content



No record found.

Microsoft Dynamics AX forum

How to combine two different Count record as one statement or output

Posted on by 1,844


I have below code which get  number of records with related owner name. Its working without any issue. But I need owner name not to be repeat and count related number of records in leads and opportunities.

My expected output:

Owner Name        No.of Leads    No.of Opportunities

ABC                           2                      5

BAC                           4                     6

My code.

static void countalluser(Args _args)
    smmLeadTable leadTable;
    smmOpportunityTable ssmmOpportunityTable;
        while select  count(OpportunityId) from ssmmOpportunityTable group by ssmmOpportunityTable.OwnerWorker
        Info(strFmt("Number of Records opportu %1 with oppor Owner %2",
        while select  count(LeadId) from leadTable group by leadTable.OwnerWorker
         Info(strFmt("Number of Records Lead %1 with lead owner %2",

  • YY Lim Profile Picture
    YY Lim 960 on at
    RE: How to combine two different Count record as one statement or output

    Not sure what is your output format, is it in table with 3 fields as above, what you could potentially do is create a new table with these 3 fields with Onwer as the primary key and insert/update with the lead and opportunity qty.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .


André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,989 Super User

Martin Dráb Profile Picture

Martin Dráb 225,588 Super User

nmaenpaa Profile Picture

nmaenpaa 101,148


Featured topics

Product updates

Dynamics 365 release plans