'Canvas app - sort table based on # records in a related table (Dataverse)

I'm building a canvas app and there is a requirement to sort accounts that you can select in a drop down based on a number of time entries that are related to this account.

I've tried approaching it with in several ways:

  1. Create a FetchXML view that aggregates the records (the view would not load in the app)
  2. Use AddColumns / CountRows functions as follows: AddColumns(Accounts, "# records", CountRows(Filter('Time Entries', ....)))

However, there is an error saying that Time Entries table is not accessible within this context.

Is there a way to achieve that? I know I can do it manually using collections, but I want to delegate the work to the Dataverse database.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source