web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Apps
Unanswered

Repeating Controls

(0) ShareShare
ReportReport
Posted on by 19

I have about 50 controls. I don't want to copy and paste and change the number like the below code.

ClearCollect(BACollect,
{BU: DDBU.Selected.Value,Country:ddCountry.Selected.Value,Hours: Value(txtHour.Text)},
{BU: DDBU_1.Selected.Value,Country:ddCountry_1.Selected.Value,Hours: Value(txtHour_1.Text)},
{BU: DDBU_2.Selected.Value,Country:ddCountry_2.Selected.Value,Hours: Value(txtHour_2.Text)},
...

);

 

Is there any easy code for this like for loop? 

For counter = 1 to 50

{BU: DDBU_.counter.Selected.Value,Country:ddCountry_counter.Selected.Value,Hours: Value(txtHour_counter.Text)},

 

or something like that?

 

 

Categories:
I have the same question (0)
  • mdevaney Profile Picture
    29,989 Moderator on at

    @ruchiga 

    Unfortunately, PowerApps cannot dynamically reference control names as you have mentioned.  There are no shortcuts here.

     

    Are you familiar with MS Excel?  I think the closest analogy I can give to what you are trying to do is the INDIRECT function in Excel which allows the user to construct cell references using variables.  I would suggest voting for the Idea below if this is a feature you would like to see in PowerApps.

     

    Link to Idea:

    https://powerusers.microsoft.com/t5/PowerApps-Ideas/INDIRECT-References/idi-p/772

  • v-xida-msft Profile Picture
    on at

    Hi @ruchiga ,

    Do you add 50 controls (Dropdown box, Text Box, ...etc) to collect data in your app?

     

    Based on the needs that you mentioned, I think it is not necessary to 50 controls in your app, instead, a Gallery control could achieve your needs.

    You could add a Gallery control in your app, then add your three data enter controls (DDBU, ddCountry and txtHour) within this Gallery.

     

    I have made a test on my side, please consider take a try with the following workaround:

    1. Add a Gallery control (Gallery1), set the Items property to following:

    [1,2,3,4,5,6,7,8,9,10,11,....,45,46,47,48,49,50]

    2. Add two Dropdown box (DDBU and ddCountry) and a Text Input box (txtHour) within above Gallery.

    3. Set the OnSelect property of the "Button" to following (modify your formula as below😞

    Clear(BACollect);
    ForAll(
     Gallery1.AllItems,
     Collect(
     BACollect,
     {
     BU: DDBU.Selected.Value,
     Country: ddCountry.Selected.Value,
     Hours: txtHour.Text
     }
     )
    )

     

    Please check and see if the following video resources would help in your scenario:

    https://www.youtube.com/watch?v=xgznk4XlPCo

    https://www.youtube.com/watch?v=DylxsXIUyDc

    https://www.youtube.com/watch?v=HUX_0AA4-Hs

     

    Best regards,

  • ruchiga Profile Picture
    19 on at

    Thanks for your explanation. I completed my app using repeating controls like what I said in my original description. I just wanted to know if there is any other option so I don't have to add 50 controls in the future. I am using the SharePoint list as a data source...

     

    ForAll(BACollect,Patch('SPList',
    Defaults('SPList'),
    {
    BU: DDBU.Selected.Value,
    Country: ddCountry.Selected.Value,
    Hours: txtHour.Text
    }
    ))

     

    How will this work with your approach for using SharePoint?

     

    Thank you for your help!

     

  • v-xida-msft Profile Picture
    on at

    Hi @ruchiga ,

    Yes, the solution I provided above could achieve your needs with SP List as data source.

     

    If you use SP List as data source in your app, please consider modify above "Submit" formula as below:

    Set the OnSelect property of the "Submit" button to following (modify your formula as below : )

    ForAll(
     Gallery1.AllItems,
     Patch( /* <-- Save data into your SP list directly, rather than save into a collection firstly */
     'SPList',
     Defaults('SPList'),
     {
     BU: DDBU.Selected.Value,
     Country: ddCountry.Selected.Value,
     Hours: txtHour.Text
     }
     )
    )

     

    Please consider take a try with above solution, then check if the issue is solved.

     

    Best regards,

  • ruchiga Profile Picture
    19 on at

    I am using two lists - subcategory and SPlist. I am trying to pull the number of items from the subcategory instead of using [1,2,3,4,5,6,7,8,9,10,11,....,45,46,47,48,49,50] in the Items property of the Gallery control. Let's say, the subcategory list has 25, 30, 35 etc. How can I do that? Thanks for your help...

  • ruchiga Profile Picture
    19 on at
  • ruchiga Profile Picture
    19 on at

    @v-xida-msft  Please see my previous post. Is it possible?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard