cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Gallery: Get value from previous row

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Power Apps Staff CarlosFigueira
Power Apps Staff

Re: Gallery: Get value from previous row

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!

View solution in original post

4 REPLIES 4
Super User
Super User

Re: Gallery: Get value from previous row

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.



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.
Anonymous
Not applicable

Re: Gallery: Get value from previous row

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?

Power Apps Staff CarlosFigueira
Power Apps Staff

Re: Gallery: Get value from previous row

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!

View solution in original post

Anonymous
Not applicable

Re: Gallery: Get value from previous row

@CarlosFigueira 

Thank you for your answer.

 

Helpful resources

Announcements
thirdimage

Power Apps Community User Group Member Badge

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

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Kudoed Authors (Last 30 Days)
Users online (3,920)