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 Platform Community / Forums / Power Apps / Gallery: Get value fro...
Power Apps
Unanswered

Gallery: Get value from previous row

(0) ShareShare
ReportReport
Posted on by

Hello everyone.

I'm doing a log with a start time and an end time. The idea is for the second onwards, the start time will be disabled and the value should be the end time of the previous row (see fig.)

image.png

I don't know how to get the value from the previous row. Do you know how can I do this?

Categories:
I have the same question (0)
  • Jeff_Thorpe Profile Picture
    6,085 Super User 2024 Season 1 on at

    Since this is a gallery then each row is an item in a collection or data source somewhere. What you need to do is when the end time is updated in the first item then you need to use patch to update the next item.

  • Community Power Platform Member Profile Picture
    on at

    Hi @Jeff_Thorpe ,

    How can I update de next item? I should use OnChange to detect when the end time is updated? How can I use Patch to update the next item in the gallery?

  • Verified answer
    CarlosFigueira Profile Picture
    on at

    PowerApps currently doesn't have a way to know the index of the item in a gallery, which is what you would need to be able to implement your logic (something like "Patch the item for the next index"). Feel free to create a new feature request in the PowerApps Ideas board for this scenario.

    One possible workaround is to, instead of working with your collection directly in the gallery, to create a new collection that contains the indices itself. For example, if your collection is created as

    ClearCollect(
     Horarios;
     { HoraInicio: Time(0; 0; 0); HoraTermino: Time(3; 0; 0); Description: "First" };
     { HoraInicio: Time(3; 0; 0); HoraTermino: Time(5; 0; 0); Description: "Second" })

    Then you can create a new collection (HorariosWithIndices) using this technique:

    ClearCollect(
     HorariosWithIndices;
     AddColumns(
     RenameColumns(
     FirstN([1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20]; CountRows(Horarios));
     "Value"; "Index");
     "HoraInicio"; Last(FirstN(Horarios; Index)).HoraInicio;
     "HoraTermino"; Last(FirstN(Horarios; Index)).HoraTermino;
     "Description"; Last(FirstN(Horarios; Index)).Description))
    

    What you have now is a new collection with the same columns as the previous one, plus a new one, called "Index". Now you can use that collection as the Items property of the gallery.

    Now on the DisplayMode property of the dropdowns for the "HoraInicio", you can use the index to tell whether it needs to be disabled:

    If(ThisItem.Index = 1; DisplayMode.Edit; DisplayMode.Disabled)

    And on the OnChange property of the "HoraTermino" dropdowns, you can update not only the current record of the new collection, but also the record for the "next" item:

    Patch(
     HorariosWithIndices;
     ThisItem;
     {
     HoraTermino: Time(Value(ddTerminoHora.Selected.Value); Value(ddTerminoMinuto.Selected.Value); 0)
     });;
    If(
     ThisItem.Index < CountRows(HorariosWithIndices);
     Patch(
     HorariosWithIndices;
     LookUp(HorariosWithIndices; Index = ThisItem.Index + 1);
     {
     HoraInicio: Time(Value(ddTerminoHora.Selected.Value); Value(ddTerminoMinuto.Selected.Value); 0)
     }))

    The attached file shows how this logic can be implemented. To open it, save it locally, then go to https://create.powerapps.com, select Open ("Abrir"), Browse ("Procurar arquivos") and find the file that you saved previously.

    Hope this helps!

  • Community Power Platform Member Profile Picture
    on at

    @CarlosFigueira 

    Thank you for your answer.

     

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