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

Create individual records in SharePoint list from a date range in Powerapps

Hello Experts,

I have a custom calendar in my canvas app where I can choose a date range. I need to add each date in the date range as a separate entry in my SharePoint List. I have a start date along with time and end date with time. I need to add each dates selected between the date range as separate items in SharePoint list. For example, my start time would be 04/06/2021 08:00 and end time would be 06/06/2020 13:00, I want to store the dates in the following format in my SharePoint List,

 

DateFromDateTo
04/06/2021 08:0004/06/2021 13:00
04/06/2021 08:00 05/06/2021 13:00
06/06/2021 08:00 06/06/2021 13:00

 

Could anyone please help me in achieving this? Your help is greatly appreciated.

Thank you in advance!

5 REPLIES 5
RandyHayes
Super User
Super User

@Anonymous 

I am not entirely clear what the source of your data sample is or where it is coming from, but if you want to create a series of records in a date range, please consider the following formula:

Collect(
    YourDataSource,
    ForAll(Sequence(DateDiff(yourStartDate, yourEndDate, Days), 0),
      {Title: "Record for " & Text(DateAdd(yourStartDate, Value), ShortDate),
       DateColumn: DateAdd(yourStartDate, Value)
      }
    )
)

This will create how ever many records needed for the time range in your datasource.

 

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!

Do it with a Timer. The timer should be set to repeat. The dteFromValue and dtToValue variable are to be set to the initial values before starting the timer.

In the OnTimerStart 
Patch( SPList, Defaults( SPList ), { DateFrom: dteFromValue, DateTo: dteToValue} ) // SPList is your SharePoint List datasource

In the OnTimerEnd check if the dteToValue is less than the input ToDate if not increment both the dteFromValue variable and dteToValue by 1 day eg. UpdateContext({dteFromValue: DateAdd( dteFromValue, 1 )})

If it is greater then stop the timer by setting the variable that started it to false.

Timer control: reference - Power Apps | Microsoft Docs
Patch function - Power Apps | Microsoft Docs
DateAdd, DateDiff, and TimeZoneOffset functions - Power Apps | Microsoft Docs

Anonymous
Not applicable

Hi @JacquesOlivier ,

Thanks for the reply. When I use UpdateContext({dteFromValue: DateAdd(dteFromValue,1)}) and UpdateContext({dteToValue: DateAdd(dteToValue,1)}) in OnTimerEnd property my dteFromValue and dteToValue shows blank. I am not able to achieve my requirement. Could you please help me on this?

Thank you!

You would need to initialize  the dteFromValue in the OnChange (do a UpdateContext({dteFromValue: FromField.SelectedDate}) of the from date field (e.g. DatePicker1) and set the initial dteToValue to the same date (but a different time)

RandyHayes
Super User
Super User

@Anonymous 

I'm not sure why you would use a timer for this when it is just as easy to do in one formula:

Collect(
    YourDataSource,
    ForAll(Sequence(DateDiff(yourStartDate, yourEndDate, Days), 0),
      {Title: "Record for " & Text(DateAdd(yourStartDate, Value), ShortDate),
       DateColumn: DateAdd(yourStartDate, Value)
      }
    )
)

Please utilize the above to simplify what you are trying to do.

_____________________________________________________________________________________
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
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,154)