Showing results for 
Search instead for 
Did you mean: 
Advocate III
Advocate III

CountRow(Table) doesn't work with a context variable as parameter


What I am trying to do is to show in a TextBox the number of records of a table that is shown in a Gallery control. This table is stored in an update context variable that it can be modified with Filters if some conditions are true.


For example, in the property "OnVisible" of Screen1 I do:

UpdateContext({table1:'Table of records'})


Then in the property "Items" of my gallery control I do:



And finally in the "Text" property of a textbox I just do:

"The number of records is: " & CountRow(table1)


The records are shown in the gallery control but I don't see the number of records in the textbox control.


Thanks in advance.


Community Champion
Community Champion

Hi @Brank

The correct syntax is CountRows, with an s at the end.

Is that the issue?

@Meneghino wrote:

Hi @Brank

The correct syntax is CountRows, with an s at the end.

Is that the issue?


I wrote the syntax incorrect here, but in my application is correct so that isn't the issue.


Thanks anyway.

Community Champion
Community Champion

Hi again, it seems to work for me.

Here is what I did:

  1. Create blank app
  2. Insert a new custom gallery (this is so that the sample data is also available), and place a text box in the template
  3. Insert a button somewhere else on the screen with OnSelect
    UpdateContext({Test: CustomGallerySample})
  4. Insert a text box somewhere else on the screen with Text
  5. Run and press the button, result in screenshot below:




PS Frankly I didn't think it was possible to set a context variable to be a table, so I am surprised this works at all.  Usually you would use a collection for this.  Any comments from the PowerApps team would be appreciated.

PPS You can even set a context variable to be a record (i.e. by using the First function), and it recognises it as a record type variable.  I was looking for how to do that for a little while, so thanks for stimulating the discovery!

Hello @Meneghino,

Can you try to do that example but using a Common Data Service entity as the Data source instead of using the table example giving by Powerapps?


Thanks in advance


Community Champion
Community Champion

Hi @Brank


I confirm that it does not work.  But it works with a simple work around, the button OnSelect should be this:

ClearCollect(PersonColl, MyCDStable); UpdateContext({Test: MyCDStable})

Then CountRows(Test) will give the correct result, assuming MyCDStable has less than 500 rows.  But you can work around that also.


I have noticed in PowerApps that if something does not work directly with the source, but it should, then it will probably work with a copy of the source in a collection.  And it will work much faster!

Helpful resources

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

Power Apps Community Call

Power Apps Community Call- January

Check out the Power Apps Community Call for January 2021

PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.


Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

Top Solution Authors
Top Kudoed Authors
Users online (9,441)