cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Resolver III
Resolver III

Clean way to get collection of weekdays with dynamic start date?

I am trying to figure out a good way to either generate a collection of weekdays based an input or by shifting a given collection based on a different start date. I can store the input as either the text value of a weekday such as "Wednesday" or the number 4. So as an example, given either Wednesday or 4 as the input, I'd want to get a collection as follows to be shown in a gallery: ["Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday"]. Given an input of Thursday or 5, the collection would be ["Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"]. It is not important to have the days tied to an actual date value, just the text value of the weekday.

 

I have gotten this to work with a big If statement (If WeekStartDate = 1, Collect(WeekRange, "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"), If(WeekStartDate = 2, Collect(WeekRange, "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday") .....).

 

I could also get this to work referencing a question I asked earlier for a different use case about generating the most recent date of a given weekday name, however I don't need this to be tied to a date. 

 

Wanted to check, is there a simpler way to do this than either of the above solutions?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Hi @Cooper01

 

I come up an idea, create a weekday collection, use index ID to filter weekdays for the next 7 days , please check my steps:

1. Put following codes to OnStart property.

 

ClearCollect(Weekday,Table({ID:1,Value:"Sunday",Num:1}, {ID:2,Value:"Monday",Num:2}, {ID:3,Value:"Tuesday",Num:3},{ID:4,Value: "Wednesday",Num:4},{ID:5,Value: "Thursday",Num:5},{ID:6,Value:"Friday",Num:6} , {ID:7,Value:"Saturday",Num:7},{ID:8,Value:"Sunday",Num:1}, {ID:9,Value:"Monday",Num:2}, {ID:10,Value:"Tuesday",Num:3},{ID:11,Value: "Wednesday",Num:4},{ID:12,Value: "Thursday",Num:5},{ID:13,Value:"Friday",Num:6} , {ID:14,Value:"Saturday",Num:7} ))

 

2. Put the following code to OnChange property of text input box

 

Set(CurrentID,LookUp(Weekday,Num=Value(TextInput2.Text)).ID)

 

3. Set Items property as below:

 

Filter(Weekday,ID>=CurrentID,ID<=CurrentID+6).Value

 

 Snipaste_2019-12-23_16-29-26.png

Sik

View solution in original post

2 REPLIES 2
Highlighted
Super User
Super User

Here's a solution I put together, where TextInput1 would be the 1-7 value you want to start with. Below will return 1-7 along with an index 0-6 of what the day is.

 

Set(SeedDay,Date(2017,1,Value(TextInput1.Text)));
ClearCollect(WeekRange,
{DayIndex: 0, Day: Weekday(SeedDay)},
{DayIndex: 1, Day: Weekday(DateAdd(SeedDay,1,Days))},
{DayIndex: 2, Day: Weekday(DateAdd(SeedDay,2,Days))},
{DayIndex: 3, Day: Weekday(DateAdd(SeedDay,3,Days))},
{DayIndex: 4, Day: Weekday(DateAdd(SeedDay,4,Days))},
{DayIndex: 5, Day: Weekday(DateAdd(SeedDay,5,Days))},
{DayIndex: 6, Day: Weekday(DateAdd(SeedDay,6,Days))}
)

 

 I used Jan 2017 because January 1st was a Sunday, so I could just build onto that.

To get the actual day name, use this formula

 

Set(SeedDay,Date(2017,1,Value(TextInput1.Text)));
ClearCollect(WeekRange,
{DayIndex: 0, Day: Text(SeedDay,"[$-en-US]dddd")},
{DayIndex: 1, Day: Text(DateAdd(SeedDay,1,Days),"[$-en-US]dddd")},
{DayIndex: 2, Day: Text(DateAdd(SeedDay,2,Days),"[$-en-US]dddd")},
{DayIndex: 3, Day: Text(DateAdd(SeedDay,3,Days),"[$-en-US]dddd")},
{DayIndex: 4, Day: Text(DateAdd(SeedDay,4,Days),"[$-en-US]dddd")},
{DayIndex: 5, Day: Text(DateAdd(SeedDay,5,Days),"[$-en-US]dddd")},
{DayIndex: 6, Day: Text(DateAdd(SeedDay,6,Days),"[$-en-US]dddd")}
)

 

---
If this answered your question, please click "Accept Solution". If this helped, please Thumbs Up.

 

Highlighted
Community Support
Community Support

Hi @Cooper01

 

I come up an idea, create a weekday collection, use index ID to filter weekdays for the next 7 days , please check my steps:

1. Put following codes to OnStart property.

 

ClearCollect(Weekday,Table({ID:1,Value:"Sunday",Num:1}, {ID:2,Value:"Monday",Num:2}, {ID:3,Value:"Tuesday",Num:3},{ID:4,Value: "Wednesday",Num:4},{ID:5,Value: "Thursday",Num:5},{ID:6,Value:"Friday",Num:6} , {ID:7,Value:"Saturday",Num:7},{ID:8,Value:"Sunday",Num:1}, {ID:9,Value:"Monday",Num:2}, {ID:10,Value:"Tuesday",Num:3},{ID:11,Value: "Wednesday",Num:4},{ID:12,Value: "Thursday",Num:5},{ID:13,Value:"Friday",Num:6} , {ID:14,Value:"Saturday",Num:7} ))

 

2. Put the following code to OnChange property of text input box

 

Set(CurrentID,LookUp(Weekday,Num=Value(TextInput2.Text)).ID)

 

3. Set Items property as below:

 

Filter(Weekday,ID>=CurrentID,ID<=CurrentID+6).Value

 

 Snipaste_2019-12-23_16-29-26.png

Sik

View solution in original post

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 (13,104)