web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Count all things from ...
Power Apps
Unanswered

Count all things from one table in another

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

The Problem:

I have a mdoels table: tableM, and an inventory table: tableT, i want to loop through my models table, tableM, and count how many of each model in tableM exsist in invnetory, tableT. I want to output the count into a collection if possible.

 

All tables are from a SQL database, and i wish i could write queries to do this, but i can not with powerapps 😞

 

I do not want to hard code the models and the countif functions because we are always adding and deleting models.

 

My resulting count collection should just be two columns like this

ModleName        TotalCount

ModelA                23

ModelB                12

ModelC                 48

 

and so on...

Categories:
I have the same question (0)
  • v-yamao-msft Profile Picture
    Microsoft Employee on at

    Hi Bri,

     

    I am not sure about the Models table. Will you create a new row for each model every time you edit the table? Or will you update the row for each model?

     

    I am working on this issue and trying to figure out a workaround.


    Best regards,
    Mabel Mao

     

  • irsimeonov Profile Picture
    46 on at

    Hi Bri

     

    One way to achieve that is though using a gallery to visualise your results and countrows() to calculate the number of model occurences (keep in mind though that the countrows() function is not delegatable to any data sources, which means that if you have more than 500 models for a specific type of model e.g. 550 ModelA models, then the countrows function will only return 500):

     

    This solution will not load your table into a collection:

     

    1. Create a gallery and set its Items property to tableM datasource

    2. Insert a text box into the gallery and set its Text property to tableM.ModelName

    3. Insert another text box to calculate the count, set its Text property as

                                 CountRows(Filter(tableT, ModelName = ThisItem.ModelName))

    Note that the Model name after tableT in the formula above is the name of the column in tableT that contains the model names, while ThisItem.ModelName gives you the current model name from tableM.

     

    A better way to visualise the count in the second text box above is by show "more or equal to 500" if the countrows equals to 500, you can use an If() statement for that.

     

    If you want to load that as a collection, then one way is to set OnVisible property of the app screen to include the following:

    1. AddColumns(ClearCollect(collectionModelName, tableM.ModelName), "Model Count", 

                                                                                                         CountRows(Filter(tableT, ModelName = ModelName))

    Note that the first ModelName in the countrows() function will come from tableT while the second ModelName will come from the collectionModelName collection.

    THe result of the above should be a collection called collectionModelName that have two columns, the first called ModelName and second - Model Count.

     

    Ivan

     

  • mutigerjh Profile Picture
    2 on at

    Just an FYI, 

    AddColumns(ClearCollect(collectionModelName, tableM.ModelName), "Model Count", 

                                                                                                         CountRows(Filter(tableT, ModelName = ModelName))

    Does not add the column to the collection.   

    I found that this does what is desired. 

    ClearCollect(collectionModelName, AddColumns('tableM', "Model Count", CountRows(ThisRecord.'tableT')))

     

    You will also need to enable the experimental options for "Record Scope One-to-Many and Many-to-Many Relationships" in settings.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 329 Most Valuable Professional

#2
11manish Profile Picture

11manish 209 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 179

Last 30 days Overall leaderboard