cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Brank
Level 8

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
Meneghino
Level 10

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?

Brank
Level 8

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.

Meneghino
Level 10

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.

Meneghino
Level 10

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!

Brank
Level 8

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,

Meneghino
Level 10

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
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (3,961)