Skip to content

How to – Different ways of getting record count (total) in Dynamics 365


Let us take a scenario, where a data migration package is running, and it either creates or updates (or deletes) a large number of records into Dynamics 365, and we want to get the count of records created/updated/deleted in the last x hour or so.

With views, we are limited to just 5000 records.

One option is to write the console app having the required QueryExpression or FetchXML condition using the Dynamics 365 SDK to get the count.

Or use the Record Counts tool of CDS.Tools

https://xrm.tools/RecordCounts

count

We can also make use of SSRS reports here.

Create a report using the report wizard, specify the criteria

In the LayOut fields window, specify Count as the summary type for grouping.

Run the report to get the count.

Another option that we have used the most is to use the FetchXML
Builder plugin to build the query, copy it.

And use it in the FetchXML / View Record Counter plugin of XrmToolBox.

Select the entity, contact, in this case, paste the FetchXML query and click Execute Count.

We will get the count.

Along with FetchXML / View Record Counter we can also use
SQL 4 CDS plugin.

Within the FetchXML builder click on Edit in SQL 4 CDS button.

The result

And now with CDS T-SQL endpoint (preview), we can use SQL Server Management Studio as well to directly write the T-SQL instead of fetch xml

https://nishantrana.me/2020/05/21/setting-up-using-sql-to-query-data-in-dynamics-365-preview/

We can also use the CDS T-SQL endpoint within the SQL 4 CDS Plugin.

https://markcarrington.dev/2020/05/24/sql-4-cds-2-1-0-the-t-sql-edition/

What if we want total record count for an Entity?

Apart from all the methods above,

  • we can use Record Counter XrmToolBox Plugin for that

https://www.xrmtoolbox.com/plugins/AndyPopkin.RecordCounter/

  • or use RetrieveTotalRecordCountRequest

https://dreamingincrm.com/2019/07/22/getting-entity-record-counts/

  • or use Count aggregrate function

https://docs.microsoft.com/en-us/previous-versions/dynamicscrm-2016/developers-guide/gg309565(v=crm.8)?redirectedfrom=MSDN#count

however, it will fail in case of more than 50000 records


‘AggregateQueryRecordLimit exceeded. Cannot perform this operation.’

To increase the limit (on-premise)- https://nishantrana.me/2012/09/06/aggregatequeryrecordlimit-exceeded-cannot-perform-this-operation/

  • Will returntotalrecordcount property of FetchXML help ?


It will be helpful if total records are less than 5000.


Hope it helps..

Advertisements

Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology ! View all posts by Nishant Rana

Posted on Categories Dynamics 365, Microsoft Dynamics 365, PowerApps, PowerPlatformTags Dynamics 365, Microsoft Dynamics 365, PowerApps, PowerPlatform

8 thoughts on “How to – Different ways of getting record count (total) in Dynamics 365”

  1. Pingback: Different ways of getting record count (total) in Dynamics 365 - 365 Community
  2. Pingback: RetrieveTotalRecordCount function to get the total number of records in Dynamics 365 – Nishant Rana's Weblog
  3. Pingback: Getting entity record counts – Nishant Rana's Weblog
  4. Thank you so much for sharing this article. Will it be possible in FetchXML to check & find only the records that have more than 1 line item in a table for a specific Order ID? For example in SQL we could do something like this:
    Order ID = 1, Order Name = Food
    Order ID = 1, Order Name = Drink
    Order ID =2, Order Name = XYZ

    SELECT OrderID, COUNT(OrderID)
    FROM Orders
    GROUP BY OrderID
    HAVING COUNT(OrderID)>1

    Order ID=2 should not be returned because it is not referenced more than once in the query result.

    How can we achieve the same in FetchXML? Would highly appreciate it if you can provide an example.

    LikeLiked by 1 person

    Reply
    1. Understood your requirement Julien. Interesting one. I think it might be too complex for fetch xml – https://docs.microsoft.com/en-us/powerapps/developer/data-platform/use-fetchxml-aggregation#group-by

      Give https://www.xrmtoolbox.com/plugins/MarkMpn.SQL4CDS/ a try here Julien. I’d also check.

      LikeLike

      Reply
      1. Thank you for your prompt reply and for providing the above documentation. Using SQL4CDS tool it is possible to transform SQL statements to a fetch XML query so we can create a complex/advanced system view that we want or maybe alter an existing system view with complex queries?

        LikeLike

        Reply
  5. I found the FetchXML Builder plugin and the FetchXML / View Record Counter plugin extremely helpful in obtaining record counts in Dynamics 365. The FetchXML Builder makes it easy to construct complex queries, and the Record Counter plugin provides a convenient way to execute the query and get the count. It’s a great combination of tools for anyone working with large data migrations.

    LikeLike

    Reply
  6. I have created a browser-based tool for the same. Check it here https://AshishVishwakarma.com/DataverseRowsCounter/ In case if below 50K rows fetchXml aggregate option can is used, for more RetrieveTotalRecordCountis used.

    LikeLike

    Reply

Please share your thoughts Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blogs I Follow

Advertisements
Advertisements

Blog Stats

  • 5,966,825 hits

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 5,660 other subscribers
Advertisements

KingswaySoft MVP

Archives

Readers

Advertisements
Advertisements

Follow me on Twitter

My Tweets

jooble

jooble
Advertisements
Microsoft Community Contributor

Top 100 CRM Blogs and Websites

Get more details ..

Advertisements

Recent Posts

My Badges – Dynamics 365 Community

Advertisements
Advertisements
Follow Nishant Rana's Weblog on WordPress.com
Log in
Nishant Rana's Weblog Website Powered by WordPress.com.

两个鬼故事起名用八笔的字起居有常名词解释好的公司起名的原则湖人vs凯尔特人2020年出生婴儿起名采阴补阳阶乘计算器好唱又能带动气氛的歌许怎样起名字免费在线名字大全起名声优战队使用翊字起名属虎的要起什么名字比较好看看影视拜伦·戴维斯et下载姓高的男起名字大秦赋剧情介绍易学取名宝宝起名字app学7画的的字起名美国疫情期间巧克力销量飙升战斗机视频重生之盾御苍穹风犬天空的少年全集16集党委书记七一讲话适合女孩起名的诗icloud注册集装箱活动房公司起名五行起名字有什么讲究美女总裁的最强高手萧逸风免费少年生前被连续抽血16次?多部门介入两大学生合买彩票中奖一人不认账让美丽中国“从细节出发”淀粉肠小王子日销售额涨超10倍高中生被打伤下体休学 邯郸通报单亲妈妈陷入热恋 14岁儿子报警何赛飞追着代拍打雅江山火三名扑火人员牺牲系谣言张家界的山上“长”满了韩国人?男孩8年未见母亲被告知被遗忘中国拥有亿元资产的家庭达13.3万户19岁小伙救下5人后溺亡 多方发声315晚会后胖东来又人满为患了张立群任西安交通大学校长“重生之我在北大当嫡校长”男子被猫抓伤后确诊“猫抓病”测试车高速逃费 小米:已补缴周杰伦一审败诉网易网友洛杉矶偶遇贾玲今日春分倪萍分享减重40斤方法七年后宇文玥被薅头发捞上岸许家印被限制高消费萧美琴窜访捷克 外交部回应联合利华开始重组专访95后高颜值猪保姆胖东来员工每周单休无小长假男子被流浪猫绊倒 投喂者赔24万小米汽车超级工厂正式揭幕黑马情侣提车了西双版纳热带植物园回应蜉蝣大爆发当地回应沈阳致3死车祸车主疑毒驾恒大被罚41.75亿到底怎么缴妈妈回应孩子在校撞护栏坠楼外国人感慨凌晨的中国很安全杨倩无缘巴黎奥运校方回应护栏损坏小学生课间坠楼房客欠租失踪 房东直发愁专家建议不必谈骨泥色变王树国卸任西安交大校长 师生送别手机成瘾是影响睡眠质量重要因素国产伟哥去年销售近13亿阿根廷将发行1万与2万面值的纸币兔狲“狲大娘”因病死亡遭遇山火的松茸之乡“开封王婆”爆火:促成四五十对奥巴马现身唐宁街 黑色着装引猜测考生莫言也上北大硕士复试名单了德国打算提及普京时仅用姓名天水麻辣烫把捣辣椒大爷累坏了

两个鬼故事 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化