cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Frequent Visitor

powerapps forall

I am using the SharePoint List as a database with a title DateStart. When a user enter a number to represent a number of days (eg: 3), I would like to create 3 date records with a starting date based on today. (DateStart (dd/mm/yyyy) should be 6/12/2020, 7/12/2020, 8/2/2020. I have try to the ForAll function and Patch function, and managed to create the datestart 3x times but with the same date 6/12/2020. How do you use the increment in the ForAll loop so the date increase? 

1 ACCEPTED SOLUTION

Accepted Solutions

@SimonDu88 

No worries, happy to help.

 

Yes, this is doable, it just becomes a little math problem - with some added on screen logic. The logic I would use is make users pick a certain day of the week to make the math easier eg Monday (you can pick Sunday or another day if you like but I'll work on Monday here).

 

So, user selects a Monday and the record inside your Patch gets updated to:

Patch(ABC, Defaults(ABC),
// add a Monday record
{RecurrenceDateDaily: DateAdd(DateValue3.SelectedDate, ((Value-1) * 7), Days)},

// add a Thursday record
{RecurrenceDateDaily: DateAdd(DateValue3.SelectedDate, ((Value-1)*7) + 3, Days)}

)

You can use the same ForAll() structure and same counter you setup before.

 

To check if a user has picked a Monday, put this is a label somewhere (oh, and also Disable/Enable your Save button depending on if a Monday has been chosen or not):

If(Weekday(DateValue3.SelectedDate)<>2,
    "Please chosen a Monday date. You cannot Save your data",
    "Your data is ready to Save")

Note: Weekday() returns a number from 1-7, Sunday=1 ,  Monday=2 ...

 

 

 

View solution in original post

12 REPLIES 12
Super User III
Super User III

Hi @SimonDu88 ,

Try DateAdd - if you want assistance with the code, let me know.

 

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.

thanks for your reply.

I would like to add a counter in the ForAll loop so the date will be different. using DateAdd() function will only created the same date being created (eg:.  the number of days = 3, the date should be  "6/12/2020, 7/12/2020, 8/2/2020" but instead the date  6/12/2020 has been repeatedly created 3x times.

could you please advise on how to create incremental inside using the forall function?

thanks in advance

 

 

Hi @SimonDu88 ,

I can think of a "messy" way immediately - this is below. I will give it some more thought if this does not suit you.

If you are not dealing with a lot of numbers (and you could restrict a user by testing the value and giving a warning and resetting the field if above this),  you could consider some cascading logic

Do the first one for one day later then
If(
   Value([user input field]) > 1,
   DateAdd + 2
);
If(
   Value([user input field]) > 2,
   DateAdd + 3
);
If(
   Value([user input field]) > 3,
   DateAdd + 4
);
and so onwards

 

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.

 

Super User II
Super User II

@SimonDu88 

Adding to what @WarrenBelz has offered, I found inspiration from this older post https://powerusers.microsoft.com/t5/Building-Power-Apps/Consecutive-date-range-into-collection/td-p/...

 

I'm actually struggling with something similar, and I'm still stuck, but this code will do what you want, I think?

ClearCollect(
    DateRange,
    AddColumns(
        FirstN(
            [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29],
            DateDiff(Today(), DateAdd(Today(),Value(TextInput1.Text),Days), Days)),
        "Day",
            "Day " & (Value + 1),
        "DateCol",
            DateAdd(Today(), Value, Days)
    )
)

I have this code in an OnSelect of a button and a TextInput called TextInput1.

Note: this is limited to Max 30 days but you can just keep adding values between the [ ... ] to meet your Max needs.

 

In Play mode, enter a value in the text input field, say 5, and this is the collection created:

DateRange.jpg

You would just need to work out how to get your number of days from your SP list into this code, shouldn't be hard though. 

 

I'll keep plugging away on my problem ...

 

Hope this helps

 

Hi @WarrenBelz ,

Please see my code as below,  I managed to patch the recurrence date "RecurrenceDateDaily" based on the number of days "DataCardValue1.Text".

(For example: if DataCardValue1.Text = 3, then my RecurrenceDateDaily will be 10/2/2020, 11/2/2020, 12/2/202, based on the date "DateValue3.SelectedDate" = today's date. However, I got 10/2/2020,10/2/2020,10/2/2020. As you can see the date does not increment.) - Please advice, thanks. Today is the deadline for my project.

please see attached Pic.

"ABC" is my SP online List

 

MY CODE:

ClearCollect(Collect_NbrRecurrence,[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31])

 

ForAll(

FirstN(Collect_NbrRecurrence, Value(DataCardValue1.Text)),

Patch(ABC,
Defaults(ABC), {RecurrenceDateDaily: DateValue3.SelectedDate} )
)

 

Hi @Eelman ,

 

Thanks very much for your input.

this is what I want but would like to patch it to the SP online list instead.

Could you please provide further advice on how to patch it back to SP online list?

Please see my most recent email to WarrenBelz, explaining my code.

your help will be much appreciated. 

Hi @SimonDu88 ,

Due to timezone issues, I will be offline for a while - I will leave you in the very capable hands of @Eelman .

Happy to have another look at it later if you have not solved it between you.

 

 

@SimonDu88 

You are basically there already, just a minor change to your code as per below.

 

Change this code snippet:

 

{RecurrenceDateDaily: DateValue3.SelectedDate}

 

to this:

 

{RecurrenceDateDaily: DateAdd(DateValue3.SelectedDate, Value, Days)}

 

 

This should work?

 

EDIT: actually, that will start you a day ahead of what you want ... change "Value" to "Value-1"

Hi @Eelman  (Genius),

 

May I allow myself to make a great announcement about you. YOU'RE SUPER GENIUS!

IT WORKS! HOORAY. 

Thank you so much for your quick  response.

if I want to do the same thing for the weekly, I would assume i should create another collection for weekly?

The situation is that user would also like to put the number of weeks (eg: 5 weeks, but every Monday and Thursday for 5 weeks). Would the concept be the same? How would you go about doing the date as this is not every day?

 

thanks in advance.

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (12,803)