web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Trying to update a col...
Power Apps
Answered

Trying to update a collection date field

(0) ShareShare
ReportReport
Posted on by 294

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.

 

Categories:
  • EricBLott Profile Picture
    248 on at

    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.

  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @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.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 220 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 189 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 139

Last 30 days Overall leaderboard