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!
JacquesOlivier
Helper I
Helper I

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

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

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
Users online (2,494)