cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dBrand
Resolver I
Resolver I

Trying to update a collection date field

I am creating a collection with one date field, as outlined below (one record example below). I then need to make a copy (col_Test2) of the same table (col_Test1) but change the dates to one year back. But it seems to blank out the field. Any idea what I'm doing wrong? I've tried it with and without DateValue in the Original table as well.

 

Original Table:

ClearCollect(col_Test1, {Date1: "10/1/2022"})

 

ClearCollect(col_Test2, col_Test1);    //Create new Table from col_Test1

UpdateIf(col_Test2, true, {Date1: DateAdd(DateValue(Date1), Years, -1)});  //Update Dates in col_Test2 to the prior year

 

Any help would be greatly appreciated! Thanks.

 

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@dBrand 

You can utilize a Patch function or a ForAll function to achieve what you are looking for.

Since you don't seem to want to actually update the date in the originating table and instead want to duplicate the data in another table, then the ForAll (which is a function that returns a Table...not a For Loop!!) is what will do the trick.

 

Consider the following formula:

ForAll(col_Test1,
    {Date1: Text(DateAdd(DateValue(Date1), -1, Years), ShortDate)}
)

Would return a table of all the dates adjusted by 1 year.

If you want that in another duplicated collection, and not using it directly, then you just put it into a collection.

Ex:

ClearCollect(col_Test2,
  ForAll(col_Test1,
    {Date1: DateAdd(Date1, -1, Years)}
  )
)

 

If you want to change all the dates in an existing collection, then the following will do that:

Patch(col_Test1, col_Test1, ForAll(col_Test1, {Date1: Text(DateAdd(DateValue(Date1), -1, Years), ShortDate)}))

 

Note: since you specified text for Date1, all of the date to text and text to date conversions in the above formulas are needed.  If you had just specified a date, they would not.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

2 REPLIES 2
EricBLott
Resolver III
Resolver III

Give this a try:

Clear(col_Test2);
ForAll(
    col_Test1,
    Collect(
        col_Test2,
        {
            Date1: DateAdd(
                DateValue(ThisRecord.Date1),
                1,
                Years
            )
        }
    )
)

---
If this answered your question, please click "Accept Solution". If this helped, please Thumbs Up.

RandyHayes
Super User
Super User

@dBrand 

You can utilize a Patch function or a ForAll function to achieve what you are looking for.

Since you don't seem to want to actually update the date in the originating table and instead want to duplicate the data in another table, then the ForAll (which is a function that returns a Table...not a For Loop!!) is what will do the trick.

 

Consider the following formula:

ForAll(col_Test1,
    {Date1: Text(DateAdd(DateValue(Date1), -1, Years), ShortDate)}
)

Would return a table of all the dates adjusted by 1 year.

If you want that in another duplicated collection, and not using it directly, then you just put it into a collection.

Ex:

ClearCollect(col_Test2,
  ForAll(col_Test1,
    {Date1: DateAdd(Date1, -1, Years)}
  )
)

 

If you want to change all the dates in an existing collection, then the following will do that:

Patch(col_Test1, col_Test1, ForAll(col_Test1, {Date1: Text(DateAdd(DateValue(Date1), -1, Years), ShortDate)}))

 

Note: since you specified text for Date1, all of the date to text and text to date conversions in the above formulas are needed.  If you had just specified a date, they would not.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

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

Check out the New Ideas Site

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

Top Solution Authors
Top Kudoed Authors
Users online (4,521)