Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

Populate Different Number in Each Gallery Item

(1) ShareShare
ReportReport
Posted on by 5,043 Super User 2025 Season 1
I have Gallery1.

In Gallery1 is Label1 and Label2.

Intent -
When 'Add SOW' button is clicked (creating item in Gallery), auto-populate
Gallery1 Label1 with next/first available number from collection (SPList1),
which has one column, 'Title', with a list of numbers from 1 to 25.

If the 'Add SOW' button is pushed a second time, the next item created should
have the next number available that doesn't match the number of above.

In the example I am able to populate Label1 using 'First(col_Collection).Title'.

However, all subsequent Gallery1 items also have '1' in Label1.

In the example, the first item was automatically numbered '1'. The next item
created should have '2' in Label1.

Label1 has -
Default:
First(col_SOW_Numbers).Value
OnChange: ClearCollect(col_SOW_Picked,Self.Text)

'Add SOW' button has -
OnSelect:
Collect(colLOADSOW, {intLOADSOW: GUID(), rem: false})

Gallery1 has -
Items:
colLOADSOW


  • WarrenBelz Profile Picture
    148,625 Most Valuable Professional on at
    Populate Different Number in Each Gallery Item
    Glad you got it working, but the reasoning for the solution you reached was not clearly evident from your numerous posts. The closest you came was in the second-last post which I had not had a chance to look at due to time zone differences.
    You post a lot here and we are all willing to help you, but please have a think about describing the problem in basic terms. 
    • I have this code (post in Text),
    • It does this now
    • I want it to do this
    • These are my list, field and control names
    • These are any error messages
    • Screenshots if they are relevant, in particular noting the Items or Defaults of controls and which list/field they apply to
    • Do not include information that is not relevant to your issue.
    Al of this is offered with nothing more in mind than to make the process of solving your issue easier and quicker.
  • Suggested answer
    Phineas Profile Picture
    5,043 Super User 2025 Season 1 on at
    Populate Different Number in Each Gallery Item
    @WarrenBelz

    Finally got it.

    My new 'Add SOW' button now has the following code, which checks
    the most recent SOW Number in the Production list and starts there for
    new items to the colLoadSOW collection, incrementing by 1 every number
    thereafter.
     
    Collect(
       colLoadSOW,
       {
          intLOADSOW: GUID(),
          rem: false,
          SOW: Text(
             Coalesce(
                Max(
                   Filter(
                      col_Production,
                      Title = EPS_Heat_Number_Fld.Text
                   ),
                   Value(SOW_Number)
                ),
                0
             ) + CountRows(colLoadSOW) + 1
          )
       }
    )

  • Phineas Profile Picture
    5,043 Super User 2025 Season 1 on at
    Populate Different Number in Each Gallery Item
     
    The ‘list’ snapshot I provided is from Production.
     
    Production is populating the ‘upper’ galleries, of which there are three (Tap, SOW, and Flux). These ‘upper’ galleries are ‘View’ only - to allow the user to see what has already occurred in the job.
     
    The screen we are looking at is for ‘Editing’ the current job.
     
    The three ‘lower’ galleries are hidden until the user clicks an option in the ‘Add’ radio control, which opens one of the three galleries.
     
    These are the galleries that are being Patched to the ‘Production’ list as updates to the job. The data for each of the ‘lower’ galleries is being saved in a collection (colTapData, colLoadSOW, colFluxData).
     
    My clarification on the formula we are working on is, yes - on first click, it is adding a gallery item and populating the SOW Number as ‘6’, which is correct, as the last SOW Number add to the list, which can seen in the ‘upper’ view only SOW gallery, is ‘5’.

    What needs to happen next is, if the user clicks the Add’ button a second time, meaning they want to add a second new SOW, the next ‘lower gallery item created should be ‘7’.
     
    As shown in the image provided, the current formula just repeated ‘6’ rather than ‘7’, which should be next in the sequence.
     
    I hope this helps.
  • WarrenBelz Profile Picture
    148,625 Most Valuable Professional on at
    Populate Different Number in Each Gallery Item
    There are still may things here that do not "fit together" (to me at least) based on the material you have posted.
    • What do you mean by The current formula provides '6', but ONLY '6' - I assume that is the result you wanted (which is what the last formula provides).
    • How does patching to colLoadSOW achieve anything when the galllery is based on colProduction and colLoadSOW has no reference to colProduction or the Production list
    • Why are you bothering with the reference number list when the value you want is simply the next one in the SOW_Number where the Heat field matches the gallery filter (again this resu;t was the last formula provided)
    Before you respond, please read this any other previous posts I have provided and give me enough information to let me understand what you need and assist you.
  • stampcoin Profile Picture
    2,744 on at
    Populate Different Number in Each Gallery Item
    @WarrenBelz thanks.👍
  • Phineas Profile Picture
    5,043 Super User 2025 Season 1 on at
    Populate Different Number in Each Gallery Item
    @WarrenBelz

    I can appreciate your frustration. My ways are not intentional.

    We are almost to the end.

    Here are the 'SOW Number' and 'SOW Tag Number' columns
    from the 'Production' list.

    These are all of the line item in the list associated with 'Heat' 4902. 


    The formula we are working on needs to filter the 'SOW' gallery based
    on the most recent patch that matches the selected 'Heat' (in this case 4902),
    and automatically enter the next 'SOW" number in the sequence from the 'SOW
    Number List'.

    In this example, the last number add to 'Publication' and associated with 4902
    was '5' (4902-5).



    The first 'Add SOW' number for a new 'SOW' for 4902 should be '6'.

    The current formula provides '6', but ONLY '6'.

    Current 'Add SOW' button formula -
    Collect(
       colLoadSOW,
       {
          intLOADSOW: GUID(),
          rem: false,
          SOW:
          Text(
             First(
                Sort(
                   AddColumns(
                      col_Production,
                      TitleVal,
                      Value(SOW_Number)
                   ),
                   TitleVal,
                   SortOrder.Descending
                )
             ).TitleVal + 1
          )
       }
    )
  • WarrenBelz Profile Picture
    148,625 Most Valuable Professional on at
    Populate Different Number in Each Gallery Item
    Still flying blind more than a bit here as you keep posting details different from earlier posts and have not answered a couple of questions I asked, however if you are wanting to add the next number in the Title column from col_Production, the formula would be something like this. Again, I need to mention that you have over-complicated it greatly by storing a number a Text in the Title column.
    Collect(
       colLoadSOW,
       {
          intLOADSOW: GUID(),
          rem: false,
          SOW: 
          Text(
             First(
                Sort(
                   AddColumns(
                      col_Production,
                      TitleVal,
                      Value(Title)
                   ),
                   TitleVal,
                   SortOrder.Descending
                )
             ).TitleVal + 1
          )
       }
    )
     
    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn    Buy me a coffee
     
  • Phineas Profile Picture
    5,043 Super User 2025 Season 1 on at
    Populate Different Number in Each Gallery Item
    @WarrenBelz

    Hang in there with me just a bit longer...

    The two galleries, on this screen. have similar formulas in them
    that look like the following (which is in the 'Tap' version of the gallery).
     
    If(IsBlank(EPS_Campaign_Number_Fld.Text),
    Filter(col_Production,!IsBlank(Tap_Number) &&
    Title = EPS_Heat_Number_Fld.Text),
    Filter(col_Production,!IsBlank(Tap_Number) &&
    Campaign = EPS_Campaign_Number_Fld.Text))

    When the screen opens these galleries auto-populate with
    data from the Production list that are associated with 
    the 'Campaign' number.

    The red circle is where the other galleries pop into view, depending
    upon which item is selected in the 'Add' radio control.

    The formula in the 'Add Tap' and 'Add SOW' buttons on this screen
    need to be able to include the last of each added to the 'Production'
    list that are associated with the 'Campaign' number (not shown, hidden
    in the gallery), and start any new 'SOW' (in the circle) from that last SOW
    Number uploaded to the 'Production' list.

    Current 'Add SOW' button formula -
    With(
       {
          _List: col_SOW_Numbers,
          _Max: Max(
             CountRows(EPS_Active_SOW_Gallery.AllItems)
          )
       },
       Collect(
          colLoadSOW,
          {
             intLOADSOW: GUID(),
             rem: false,
             SOW: LookUp(
                    col_SOW_Numbers,
                    Value > Max(
                CountRows(EPS_Active_SOW_Gallery.AllItems)
                )
               
            ).Value
        }
    ))

    Example:
    if last 'SOW' was '3' the 'Add SOW' button should open the SOW gallery
    and populate the SOW Number with '4'.

  • WarrenBelz Profile Picture
    148,625 Most Valuable Professional on at
    Populate Different Number in Each Gallery Item
    Now totally lost - if the Items of (this other) gallery is 
    Filter(
       col_Production,
       !IsBlank(SOW_Number) && 
       Campaign = EPS_Campaign_Number_Fld.Text
    )
    how does colLoadSOW have any connection to any record in the gallery and (as I asked before) how are you then updating your List from this gallery ? Also is the Add SOW button inside or outside the gallery ?
  • Phineas Profile Picture
    5,043 Super User 2025 Season 1 on at
    Populate Different Number in Each Gallery Item
    @WarrenBelz

    I have three screens doing similar but different things.

    What we have so far is working on the other two screens, based on how they work.

    On this last screen the 'Tap' and 'SOW' (two different galleries, but the formula will work
    in both with a tweak or two) 'Add' buttons formula needs to include a way to know the last
    'SOW' or 'Tap' Number added to the col_Production (Production List), and start the new 'Tap'
    or 'SOW' count there.

    In the below example the first new SOW number would be '6', as '5' is showing in the gallery
    above and was the last SOW add for the 'Campain'.

    If this was a new 'Heat' (which is the case on the other screen, which is why there is no problem
    there), starting at '1' would be correct. On this Update version of the screen the new SOW number
    needs to pick up where the last 'Heat' associated SOW number finished, '5'.

    I tried to reference the 'existing' gallery directly in my edited formula. It returned the '6' as required,
    but it returns ONLY 6.

    The existing SOW gallery has the following in its items (the 'Campaign' number is hidden in the gallery) -
    Filter(col_Production,!IsBlank(SOW_Number) && Campaign = EPS_Campaign_Number_Fld.Text))

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

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 791 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 410

#3
mmbr1606 Profile Picture

mmbr1606 275 Super User 2025 Season 1