cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Brank
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
Meneghino
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?



Hello,

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

 

Thanks anyway.

Meneghino
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
    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
Community Champion
Community Champion

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

Regards,

Meneghino
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

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (95,425)