cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AsgeirAlbretsen
Level: Powered On

Get the amount of items in a gallery

I'm trying to create an If statement that depends on the amount of items in a gallery. From a quick Googling session, I found that "If(CountRows(Gallery_1.AllItems) = 1, 570, 4)" should do the trick, but I'm getting an error. Gallery_1.AllItems says "The specified property is not accesible in this context", and the CountRows then gives "The function 'CountRows' has some invalid arguments". The If is under the X value of the first item in the gallery. My goal is to position the first item based on the amount of items in the gallery. Any ideas on how to fix the errors?

7 REPLIES 7
SimonPiquer
Level 8

Re: Get the amount of items in a gallery

Hi!

 

You code works for me when I try it out. What happens if you create a new label with the Text property set to 

CountRows(Gallery_1.AllItems)

Do you get the correct number of rows then? 

What is the datasource you are using/what is the gallery's Items property set to?

Could you provide some screenshots?

 

Thanks!

AsgeirAlbretsen
Level: Powered On

Re: Get the amount of items in a gallery

It works perfectly fine in a label for me as well! My data source is SharePoint and the items property is set to:

 

"If( IsMatch(TextInput_ProjectNumSearch.Text, ""), Filter(Documents, StartsWith('Project number', "1234567890")), Filter(Documents, StartsWith('Project number', TextInput_ProjectNumSearch.Text)))"

 

@SimonPiquer 

Sijts
Level 8

Re: Get the amount of items in a gallery

If(CountRows(Gallery3_1.AllItems) = 1,1000,500)

does work, only not if it is part of the gallery it is calculating about.

 

What could try is to set a calculation which says:

If(ThisItem.field1 = First(Datasource of gallery).field1, 100, 200)

AsgeirAlbretsen
Level: Powered On

Re: Get the amount of items in a gallery

@Sijts 

 

That is a really odd limitation. I need to know the amount of items in the gallery, to edit the gallery position. If there is only 1 item, output 570. If it's 2 items output 400 etc. This would be very easy if I could just use AllItems. Limiting the ability to edit values makes sense when there is a danger of infinite loops, but editing the position should have no danger of infinite loops.

Sijts
Level 8

Re: Get the amount of items in a gallery

almost an infinity loop but really dangerous for performance.

imagine that for each record you are gonna read all records from the list.

so a list of 200 items: you can say for each item i will get all items.

it will call 200 * 200 records 40000!!

 

that's why Smiley Happy

AsgeirAlbretsen
Level: Powered On

Re: Get the amount of items in a gallery

@Sijts 

 

That makes sense. I'm sure I will never get more than 5 files at once though. Do you know of a way to circumvent this limitation?

Sijts
Level 8

Re: Get the amount of items in a gallery

If you only want to check if a record is the first one of the gallery, check my previous answer about the comparison of thisitem.value againt the datasource of the gallery with a first applied to it

Helpful resources

Announcements
firstImage

PowerApps Monthly Community Call!

Join us next Wednesday for our Demo Extravaganza, October 16, 2019 8am PDT.

firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

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

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 518 members 4,678 guests
Please welcome our newest community members: