cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
bobgodin
Helper II
Helper II

Trying to increment date field in a Gallery using ForAll and Sequence

I have a Gallery (Child) that contains a variable number of records linked to a Parent form. The Gallery has a tripdate field where I want to set the first record's date to tomorrow and then increment subsequent records by 1 day - the Gallery is displaying dates from a field trip the user is recording. There are a few other fields in the Gallery; destination, activity, localcontact etc

 

The Gallery's items property is: Filter(TripDetails,tripid=Value(Gallery2.Selected.tripid.Text)) as it is getting the ID from another screen and another Gallery. I have found a post which explained how to use the Sequence function to increment the dates and if I put this on theGallery's items property: ForAll(Sequence(15), {date: DateAdd(Today(), Value, Days)}) and then this on the TextInput for the tripdate: Text(ThisItem.date, ShortDate, "en-GB") it works and the dates are displayed correctly but of course I lose the Filter and the subsequent data.   What I need to do is combine the Filter statement with the ForAll so I get all the fields in the Gallery plus the incrementing dates.

 

I hope I have explained that well enough....

 

Can anyone please assist?

2 ACCEPTED SOLUTIONS

Accepted Solutions

Hi @bobgodin ,

 

Sorry for my incorrect method. I made an App to repro the issue and then find a way to achieve your need. Please try and set Items property of the Gallery:

 

ForAll(
    Sequence(
        CountRows(
            Filter(
                TripDetails,
                tripid=Value(Gallery2.Selected.tripid.Text)
            )
        )
    ) As SS,
    Last(
        FirstN(
            AddColumns(
                Filter(
                    TripDetails,
                    tripid=Value(Gallery2.Selected.tripid.Text)
                ),
                "Date",
                DateAdd(Today(),SS.Value,Days)
            ),
            SS.Value
        )
    )
)

 

 

Now, Default of Text Input boxes within the Gallery need only ThisItem.ColumnName.

 

Best regards, 

Community Support Team _ Jeffer Ni

If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

bobgodin
Helper II
Helper II

thanks @v-jefferni that did the trick - I really appreciate the time and effort you took to respond to my query - thank you again 🙂

View solution in original post

10 REPLIES 10
v-jefferni
Community Support
Community Support

Hi @bobgodin ,

 

Am not sure if I understand correctly. The logic I assume is, for all the items of the TropDetails list that tripid equal to Gallery2 selected tripid, in the child Gallery make the date column from tomorrow and on. So the child Gallery Items:

 

ForAll(
    CountRows(Filter(TripDetails,tripid=Value(Gallery2.Selected.tripid.Text))) As SS,
    AddColumns(
        Filter(TripDetails,tripid=Value(Gallery2.Selected.tripid.Text)),
        "Date",
        DateAdd(Today(), SS.Value, Days)
    )
)

 

 

Best regards,

Community Support Team _ Jeffer Ni

If this post helps, then please consider Accept it as the solution to help the other members find it.

Hi @v-jefferni thanks a lot for that code but I think we may be missing a bracket or something else...see screenshot attached

cheers

Bob

Hi @bobgodin ,

 

Not a bracket, but the Sequence function:

ForAll(
    Sequence(CountRows(Filter(TripDetails,tripid=Value(Gallery2.Selected.tripid.Text)))) As SS,
    AddColumns(
        Filter(TripDetails,tripid=Value(Gallery2.Selected.tripid.Text)),
        "Date",
        DateAdd(Today(), SS.Value, Days)
    )
)

 

Best regards,

Community Support Team _ Jeffer Ni

If this post helps, then please consider Accept it as the solution to help the other members find it.

Hi @v-jefferni thanks for that - the items code is now looking good but my gallery's textboxes are not happy now - see attached screenshots. The Default property for these textboxes are ThisItem.destination, ThisItem.activity, ThisItem.accomodation etc - do I need to change these now?  sorry bit of a newbie to Powerapps 🙂

Hi @bobgodin ,

 

As the formula I suggested was using the AddColumns function to reinforce the original table of the filter result with a Date column, the result table will share a basically same structure as your original table, which means they will have same columns and an additional "Date" column. You can select the whole formula and there will be a small arrow appear below the formula bar, click the arrow then you will see the result table with all its columns:

vjefferni_0-1664268025412.png

Then you could use ThisItem.ColumnName for respective Text Input box.

 

Best regards,

Community Support Team _ Jeffer Ni

If this post helps, then please consider Accept it as the solution to help the other members find it.

Hi @v-jefferni thank you but I don't understand what I have to do to be able to see the datasource for my Gallery...

Hi @bobgodin ,

 

Please check Items property of the Gallery.

 

Best regards,

Community Support Team _ Jeffer Ni

If this post helps, then please consider Accept it as the solution to help the other members find it.

Hi @v-jefferni sorry to be a pain - I have got this far with selecting Items property - I can see it is ThisItem.Value - see screenshot...and I can see the fieldnames below this but when I choose activity, for example, I get "Expected Text value" and the red underline - I tried adding .Text to the end of it but that didn't work.....I think I am close lol

thanks

Bob

Hi @bobgodin ,

 

Sorry for my incorrect method. I made an App to repro the issue and then find a way to achieve your need. Please try and set Items property of the Gallery:

 

ForAll(
    Sequence(
        CountRows(
            Filter(
                TripDetails,
                tripid=Value(Gallery2.Selected.tripid.Text)
            )
        )
    ) As SS,
    Last(
        FirstN(
            AddColumns(
                Filter(
                    TripDetails,
                    tripid=Value(Gallery2.Selected.tripid.Text)
                ),
                "Date",
                DateAdd(Today(),SS.Value,Days)
            ),
            SS.Value
        )
    )
)

 

 

Now, Default of Text Input boxes within the Gallery need only ThisItem.ColumnName.

 

Best regards, 

Community Support Team _ Jeffer Ni

If this post helps, then please consider Accept it as the solution to help the other members find it.

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Power Apps Ideas

Changes to Ideas Coming

We are excited to announce a new way to share your ideas for Power Apps!

Top Solution Authors
Top Kudoed Authors
Users online (2,138)