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

Given the functions available in PowerApps' PowerFx, create a list of dates consisting of every Friday as of today.

My goal is to create records in a Dataverse table with a Friday field date, for every week for the rest of this year. 

I'll be using ForAll() and Patch() functions to create the records in the table, but for now I need to figure out how to get each Date.

 

So for example, 

If today was January 7, 2022 (the first Friday of the month of January). My list/collection would look like [Date(1/7/2022), Date(1/14/2022), Date(1/21/2022), Date(1/28/2022), Date(2/4/2022), ... ]

 

Functions I'll be using would be Today(), Collect() and maybe WeekNum(Today()) and Weekday(Today())

 

Any help towards the solution would be helpful, thanks in advance! 🙂 

1 ACCEPTED SOLUTION

Accepted Solutions
TheRobRush
Super User
Super User

In order to get every friday from here on out to end of year you are going to need to something like this 

 

onselect of a button, collects all fridays for current year from this day until end

ClearCollect(Fridays,
Filter(

ForAll(
///START DATE RANGE, 
            Sequence(
                    DateDiff(
		///SET START DATE
                            Now(),
        ///SET END DATE
                            Date(Year(Now()),12,31),
        ///RETURN DIFFERENCE IN DAYS
                            Days
                            )
                    ),
        If(
                ////THIS CALCULATES IF THE DAY IN QUESTION IS A WEEKEND
                Weekday(DateAdd('Day 1'.SelectedDate,ThisRecord.Value-1))=6,
                                            ///SAVE THE DATE
                                            DateAdd('Day 1'.SelectedDate,ThisRecord.Value-1))),
                                            ///FILTER OUT NULL ENTRIES
                                            IsBlank(Value)=false))
_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!

View solution in original post

3 REPLIES 3
timl
Super User
Super User

@just_an_intern 

This should hopefully get you started.

ForAll(Sequence(52,0,1),
       {Date:DateAdd(DateValue("2022-01-07"),Value*7)}
)

 

timl_0-1656515664968.png

 

TheRobRush
Super User
Super User

In order to get every friday from here on out to end of year you are going to need to something like this 

 

onselect of a button, collects all fridays for current year from this day until end

ClearCollect(Fridays,
Filter(

ForAll(
///START DATE RANGE, 
            Sequence(
                    DateDiff(
		///SET START DATE
                            Now(),
        ///SET END DATE
                            Date(Year(Now()),12,31),
        ///RETURN DIFFERENCE IN DAYS
                            Days
                            )
                    ),
        If(
                ////THIS CALCULATES IF THE DAY IN QUESTION IS A WEEKEND
                Weekday(DateAdd('Day 1'.SelectedDate,ThisRecord.Value-1))=6,
                                            ///SAVE THE DATE
                                            DateAdd('Day 1'.SelectedDate,ThisRecord.Value-1))),
                                            ///FILTER OUT NULL ENTRIES
                                            IsBlank(Value)=false))
_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!
TheRobRush
Super User
Super User

Actually chaneg the end date to, otherwise it won't count a friday in december if december 31st which will happen in 2027

        ///SET END DATE
                            DateAdd(Date(Year(Now()),01,01),1,Years),
_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!

Helpful resources

Announcements
Super User 2 - 2022 Congratulations 768x460.png

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

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.

<
Users online (4,607)