cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ericonline
Community Champion
Community Champion

AddColumns and DateDiff on a Collection?

Hello,

I've got the "PowerApps encountered an internal error..." message in my Collection. Need some guidance here. 

Scenario:

- Trying to use AddColumns to create a calculated column showing the difference between two timestamps

- Collection Items property is set to:

AddColumns(
    colTimeline,
    "timeDiff",
    DateDiff(
        ThisRecord.activityTime, 
        LookUp(
            colTimeline, id = (ThisRecord.id - 1), 
            activityTime
        )
    )
)

 - No red "x"'s, but the "timeDiff" column shows an internal error:

ericonline_0-1611709929560.png

Can anyone see what I'm missing here? 
Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @ericonline ,

I cannot test this, but try

With(
   {
      wTimeLine:
      RenameColumns(
         colTimeline,
         "id",
         "id1"
      )
   },
   AddColumns(
      colTimeline,
      "timeDiff",
      DateDiff(
         activityTime, 
         LookUp(
            wTimeline, 
            id1 = id - 1
         ).activityTime
      )
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

3 REPLIES 3
Jacky_Shen
Resolver IV
Resolver IV

Hi @ericonline ,

 

Is that because you are adding a column to a collection, but at the same time, you are using the same collection to find a column's value, will it work if you change the data source of the function LookUp to the table's name instead of the collection's name?

 

Just a thought...

ericonline
Community Champion
Community Champion

Hi @Jacky_Shen , I'm not sure. 

There actually isn't a DataSource involved here. The Collection is all created in the app from user entry. At some point, I'll Patch() it to a DataSource.

- The workflow is:

- User selects an Activity, enters a Time and some notes

- Clicks "Add"

- Record is added to Collection using Collect()

- The second Activity a user creates will do the same, BUT, I want the app to calculate the duration between events here (and for all subsequent events).

- Thats why I'm attempting to use AddColumns. 

 

Maybe I should just do this all on a hidden label and add it to the collection as part of Collect() ?

Hi @ericonline ,

I cannot test this, but try

With(
   {
      wTimeLine:
      RenameColumns(
         colTimeline,
         "id",
         "id1"
      )
   },
   AddColumns(
      colTimeline,
      "timeDiff",
      DateDiff(
         activityTime, 
         LookUp(
            wTimeline, 
            id1 = id - 1
         ).activityTime
      )
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (1,703)