cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Advocate III
Advocate III

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

Hello,

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:

table1

 

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.

Regards,

6 REPLIES 6
Highlighted
Community Champion
Community Champion

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

Hi @Brank

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

Is that the issue?

Highlighted
Advocate III
Advocate III

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


@Meneghino wrote:

Hi @Brank

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

Is that the issue?



Hello,

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

 

Thanks anyway.

Highlighted
Community Champion
Community Champion

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

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
    CountRows(Test)
  5. Run and press the button, result in screenshot below:

__.JPG

 

 

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.

Highlighted
Community Champion
Community Champion

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

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!

Highlighted
Advocate III
Advocate III

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

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

Regards,

Highlighted
Community Champion
Community Champion

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

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

Announcements
Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (10,072)