cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SaWu
Impactful Individual
Impactful Individual

How do you count the number of records in a DataSource robustly independent of Delegation?

Hello

Please be so kind as to read my full post before responding.
Thank you for your consideration.

I am building a PowerApp for CDS/Dynamics using currently PowerApps 3.19075.21.

I am trying to find out the number of entries in a datasource, or in a "Relational Data field/table", but I don't know a robust way to retrieve this number of entries (i.e. guaranteed to give me the right result).

For example, given two entitities, "Auftrag (WA)" (Plural "Aufträge (WA)") and "Auftragsposition (WA)" (Plural "Auftragsposition (WA)"), with Auftragsposition containing a LookUp field to Auftrag, thus creating the relational data field/table 'Auftrag (WA)'.'Auftragsposition (WA)', I might want to know the number of Auftrag records or the number of Auftragsposition records associated with a given Auftrag record.
I.e. something like:

CountRows([@'Aufträge (WA)']) & "
" & CountRows([@'Auftragsposition (WA)']) & "
" & CountRows(Filter([@'Auftragsposition (WA)'], 'Auftrag (Suche)'.'Auftrag (WA)'=First([@'Aufträge (WA)']).'Auftrag (WA)')) & "
" & CountRows(First([@'Aufträge (WA)']).'Auftragsposition (WA)')

This yields lots of delegation warnings
image.png
Thus, for large datasets, there is the potential of those formulas not working, see also
image.png
As far as I understand, using Collect first and using CountRows removes the delegation warning but won't solve my problem as Collect will also only be returning the first X entries.
https://powerusers.microsoft.com/t5/General-Discussion/ClearCollect-for-more-than-2000-records/m-p/1...
I understand that I can use a (scheduled) rollup field if I don't care that those numbers will only be available after scheduled rollup times.
However, I require a robust way to retrieve those numbers, say, in Button.OnSelect.

 

  1. Is there a function beside CountRows that I don't know about and that will do what I want?
  2. Is there any robust way to "simply" get those numbers I want irrespective of actual size of that number and, in particular, irrespective of delegation?


Thank you,
    Sa.

3 REPLIES 3
RezaDorrani
Dual Super User II
Dual Super User II

Hi @SaWu 

 

within PowerApps this is not possible with all the delegation issues 

 

And even with delegation, PowerApps loads data in batches

 

your best bet would be to trigger a Flow which would perform all those calculations and then return the result (but this would be a long way to achieve it)

 

Regards,

Reza Dorrani

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

v-yutliu-msft
Community Support
Community Support

Hi @SaWu ,

Firstly, it's not supported to avoid delegation by some special ways.

Delagation is PowerApps iteself's limit.

Secondly, if your record number is less than 2000, then just change this limit to 2000, you do not need to worry about the effect of delegation.delegation.jpg

Delegation is for large record that is larger than 2000, which may lead to wrong result.

 

Thirdly, if your data source's record is lager than 2000, you could only use delegable functions to avoid the effect of delegation.

Here's a doc about delegable functions of CDS for your reference, please modify your formula:

https://docs.microsoft.com/en-us/connectors/commondataservice/

 

If you can not modify your formula by only using delegable functions, I suggest you use Flow instead of PowerApps.

 

 

 

 

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
MarcoLotscherNC
Helper III
Helper III

You can retreive the total amount of records by using the following odata query within a cloud flow: 
https://ENVIRONMENTNAME.crmXYZ.dynamics.com/api/data/v9.1/RetrieveTotalRecordCount(EntityNames=['YOU...

 

This work fine for large lists too (> 5000 record).

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (1,761)