cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
gautmish
Helper III
Helper III

iterate collection depend on variable "i"

Hi,

I have one collection ex: answercol . I want to get something like below .

 

Filter(Answer,  Section in SectionGallery.Selected.Title1.Text)[i].Title

 

where i can pass the value of "i" on button click.

 

Thanks

Gautam Mishra

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @gautmish,

 

I agree with @CarlosFigueira's thought almost. In addition, you could also consider take a try with the following workaround:

  • Set OnVisible property of Screen1 of your PowerApps app to following formula:
ClearCollect(Answer,{ID:1,Title:"Answer1",Description:"This is my first answer"},{ID:2,Title:"Answer2",Description:"This is my second answer"},{ID:3,Title:"Answer3",Description:"This is my third answer"});Set(Iterator,1)
  • Add a Button control within Screen1 of your PowerApps app. Set OnSelect property of this Button control to following formula:
ClearCollect(FilterRecord,Remove(FirstN(Answer,Iterator),FirstN(Answer,Iterator-1)));Set(Iterator,Iterator+1)
  • Add a Gallery control within Screen1 of your PowerApps app, set Items property of this Gallery control to following formula:
FilterRecord

My PowerApps's configuration as below:1.JPG

 

2.JPG

 

3.JPG

 

 

 

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
v-xida-msft
Community Support
Community Support

Hi @gautmish,

 

Could you please share a bit more about your Collection?

Do you want to use the Filter(...)[i] formula to reference each item within the filtered collection (a table)?

 

If you want to use the Filter(...)[i] formula to reference each item within the filtered collection (a table), I afraid that there is no way to achieve your needs in PowerApps app currently, if you would like this feature to be added in PowerApps app, please submit an idea to PowerApps Ideas Forum:

https://powerusers.microsoft.com/t5/PowerApps-Ideas/idb-p/PowerAppsIdeas

 

Currently, if you want to iterate collection within PowerApps app, you could consider take a try to use the ForAll() function to achieve your needs.

 

More details about ForAll function, please check the following article:

ForAll fcuntion in PowerApps app

 

 

Best regards,

Kris

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Kris,

 

Thanks for the reply .

 

What I exactly want is . I have a collection where i have multiple column (ID, title,description). I have one button . on the first click it should show the 1 row of collection and on second click it should show the 2nd row of the collection.

 

Thanks

Gautam Mishra

Hi Gautam,

 

You can use a combination of the FirstN and Last functions to access an item in the collection based on its index. For example, to access the i-th element, of a collection "coll", you can use this expression:

Last(FirstN(coll, i))

In your case, since you have a filter expression, you should also consider sorting it; the order of a filtered expression isn't guaranteed to be the same for all times it is executed.

Hi @gautmish,

 

I agree with @CarlosFigueira's thought almost. In addition, you could also consider take a try with the following workaround:

  • Set OnVisible property of Screen1 of your PowerApps app to following formula:
ClearCollect(Answer,{ID:1,Title:"Answer1",Description:"This is my first answer"},{ID:2,Title:"Answer2",Description:"This is my second answer"},{ID:3,Title:"Answer3",Description:"This is my third answer"});Set(Iterator,1)
  • Add a Button control within Screen1 of your PowerApps app. Set OnSelect property of this Button control to following formula:
ClearCollect(FilterRecord,Remove(FirstN(Answer,Iterator),FirstN(Answer,Iterator-1)));Set(Iterator,Iterator+1)
  • Add a Gallery control within Screen1 of your PowerApps app, set Items property of this Gallery control to following formula:
FilterRecord

My PowerApps's configuration as below:1.JPG

 

2.JPG

 

3.JPG

 

 

 

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Hi kris ,

 

Thanks for the reply. 

 

I have tried below formula and that worked perfectly for me .

 

First(Filter(Answer,And(AuditNumber= SurveyNo.Text,(Value(UID) = First(Filter(Answer,Section = Gallery2.Selected.Title1.Text)).UID+i)))).Title

 

I took a variable "i"  and increaing it depend on the button click

 

Thanks

Gautam Mishra

 

 

I have done By this Logic

Select(Parent);RemoveIf(ProductList, Index = Gallery2.Selected.Index);

 

Clear(collection2);

ForAll(ProductList,
Collect(collection2,
{
Index: CountRows(collection2)+1,
Comments: Comments,
SalesPrice: SalesPrice,
Discount: Discount,
Quantity: Quantity,
Height: Height,
Width: Width,
Color: Color,
ProfileSet: ProfileSet,
Product: Product,
Group: Group
}
)
);
Clear(ProductList);
ForAll(collection2,
Collect(ProductList,
{
Index: Index,
Comments: Comments,
SalesPrice: SalesPrice,
Discount: Discount,
Quantity: Quantity,
Height: Height,
Width: Width,
Color: Color,
ProfileSet: ProfileSet,
Product: Product,
Group: Group
}
)
);
Set(ValueToIncrement, CountRows(ProductList));

wrote: -Jayprakash Birla

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (1,682)