cancel
Showing results for
Did you mean:
Frequent Visitor

## How get the first / second / third / fourth date from the selected day?

Hi all,
I want to take a few dates from the selected day like this case:

1. If I choose 7/1/2020 to 10/31/2020, and choose The First Sunday of Every Month, then 7/5/2020,  8/2/2020, 9/6/2020, 10/4/2020 will be saved to new collection.
2. If I choose 7/1/2020 to 9/1/2020, and choose The Third Wednesday of Every Month, then 7/15/2020,  8/19/2020 will be saved to new collection.
3If I choose 7/1/2020 to 10/1/2020, and choose The Last Friday of Every Month, then 7/31/2020,  8/28/2020,  9/25/2020 will be saved to new collection.
How to get date on the selected day based on the case above? Any help is appreciated. Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support

Hi @AndiNoya ，

Do you want to list dates based on the 2 selected dates and selected which weekday?

Actually, this logic is very complex.

There's no directly function to get the dates based on selected which weekday. So the only solution is to list conditions one by one.

What's more, if there' no rule to select start date and end date, the logic will be more complex.

So I suggest you only select the first day of the month in the start date and end date, like 7/1/2020,10/1/2020,....

I only list some conditions blow, you could complete the rest based on my formulas:

1)datepicker3's OnChange:

``Set(startweek,Weekday(DatePicker3.SelectedDate))``

//start day weekday

2)datepicker4's OnChange:

``Set(endmonthweek,Weekday(Date(Month(DatePicker4.SelectedDate),1,1)));Set(endweek,Weekday(DatePicker4.SelectedDate))``

//end day weekday

3)drop down4's OnChange:

``Set(num,If(Dropdown4.Selected.Value="First",1,Dropdown4.Selected.Value="Second",2,Dropdown4.Selected.Value="Third",3,Dropdown4.Selected.Value="Fourth",4,Dropdown4.Selected.Value="Fifth",5))``

4)drop down5's OnChange:

``Set(week,If(Dropdown5.Selected.Value="Monday",2,Dropdown5.Selected.Value="Tuesday",3,Dropdown5.Selected.Value="Wednesday",4,Dropdown5.Selected.Value="Thursday",5,Dropdown5.Selected.Value="Friday",6,Dropdown5.Selected.Value="Saturday",7,Dropdown5.Selected.Value="Sunday",1))``

5)the label to list dates:

``````If(startweek<=week,
&","&
//date in first month
If(
Month(DatePicker3.SelectedDate)+1=Month(DatePicker4.SelectedDate),
""
)&","&
//if endmonth-startmonth=1,date in second month
If(Month(DatePicker3.SelectedDate)+1<Month(DatePicker4.SelectedDate),
//if endmonth-startmonth>=2,date in second month
If(Month(DatePicker3.SelectedDate)+2<Month(DatePicker4.SelectedDate),
//if endmonth-startmonth>=3,date in third month(choose 7/1/2020 to 10/1/2020)
If(Month(DatePicker3.SelectedDate)+10<Month(DatePicker4.SelectedDate),
//if endmonth-startmonth>=11,date in eleventh month (choose 1/1/2020 to 12/1/2020)
If(num=1&&Weekday(DatePicker4.SelectedDate)=week,DatePicker4.SelectedDate,"")
//the last month ``````

Then you could use Split function to split these dates. For example:

``ClearCollect(collection1,Split(Label1.Text,","))``

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 REPLIES 2
Community Support

Hi @AndiNoya ，

Do you want to list dates based on the 2 selected dates and selected which weekday?

Actually, this logic is very complex.

There's no directly function to get the dates based on selected which weekday. So the only solution is to list conditions one by one.

What's more, if there' no rule to select start date and end date, the logic will be more complex.

So I suggest you only select the first day of the month in the start date and end date, like 7/1/2020,10/1/2020,....

I only list some conditions blow, you could complete the rest based on my formulas:

1)datepicker3's OnChange:

``Set(startweek,Weekday(DatePicker3.SelectedDate))``

//start day weekday

2)datepicker4's OnChange:

``Set(endmonthweek,Weekday(Date(Month(DatePicker4.SelectedDate),1,1)));Set(endweek,Weekday(DatePicker4.SelectedDate))``

//end day weekday

3)drop down4's OnChange:

``Set(num,If(Dropdown4.Selected.Value="First",1,Dropdown4.Selected.Value="Second",2,Dropdown4.Selected.Value="Third",3,Dropdown4.Selected.Value="Fourth",4,Dropdown4.Selected.Value="Fifth",5))``

4)drop down5's OnChange:

``Set(week,If(Dropdown5.Selected.Value="Monday",2,Dropdown5.Selected.Value="Tuesday",3,Dropdown5.Selected.Value="Wednesday",4,Dropdown5.Selected.Value="Thursday",5,Dropdown5.Selected.Value="Friday",6,Dropdown5.Selected.Value="Saturday",7,Dropdown5.Selected.Value="Sunday",1))``

5)the label to list dates:

``````If(startweek<=week,
&","&
//date in first month
If(
Month(DatePicker3.SelectedDate)+1=Month(DatePicker4.SelectedDate),
""
)&","&
//if endmonth-startmonth=1,date in second month
If(Month(DatePicker3.SelectedDate)+1<Month(DatePicker4.SelectedDate),
//if endmonth-startmonth>=2,date in second month
If(Month(DatePicker3.SelectedDate)+2<Month(DatePicker4.SelectedDate),
//if endmonth-startmonth>=3,date in third month(choose 7/1/2020 to 10/1/2020)
If(Month(DatePicker3.SelectedDate)+10<Month(DatePicker4.SelectedDate),
//if endmonth-startmonth>=11,date in eleventh month (choose 1/1/2020 to 12/1/2020)
If(num=1&&Weekday(DatePicker4.SelectedDate)=week,DatePicker4.SelectedDate,"")
//the last month ``````

Then you could use Split function to split these dates. For example:

``ClearCollect(collection1,Split(Label1.Text,","))``

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Frequent Visitor

Hi @v-yutliu-msft ,
I tried the formula you gave and it worked. but in 3rd case(The Last Friday of Every Month) it gave the wrong date

Announcements

#### December 2023 User Group Update: Welcoming New Groups and Upcoming Events

A new month means it's time to celebrate and welcome the new user groups that have joined our community. We are excited to announce that we have more than 8 New Groups, which is no surprise after the amazing Microsoft Power Platform Conference. This month, we are breaking them out by the different community categories. If your group is listed here, give this post a kudo so we can celebrate with you! Don't forget to take a look at the many events happening near you or virtually! It's a great time of year to connect and engage with User Groups both locally and online.   Please Welcome Our NEW User Groups   Power Platform: PowerIT User Group: Nottingham Power Platform User Group: Bergen Power Platform User Group: Danmark Nashville Power Platform User Group Microsoft Ambassador Program y Mujer Latina Technolochicas NCWIT Community Copilot Studio:  Copilot User Group Italia Dynamics365: Dynamics User Group AdriaticDynamic 365 Azerbaijan   December User Group Events   01 Dec 2023 Aprendiendo Desarrollo web, creando mi primer power app y power page. 01 Dec 2023 Q4 Hybrid Philadelphia Dynamics 365 & Power Platform User Group Meeting05 Dec 2023APAC Dynamics 365 FastTrack Bootcamp - BI and Analytics07 Dec 2023Bay Area Power Platform Meetup: Learn, Share, and Connect07 Dec 2023Indiana D365/AX December User Group Meeting07 Dec 2023Dynamics User Group Meeting: Houston09 Dec 2023 December '23 - NEW Power Apps User Group Meeting - Online 12 Dec 2023December Cleveland Power Platform User Group Meeting12 Dec 2023 RW2 Data Stewardship Open Forum Discussion 13 Dec 2023  Black Country Power Platform User Group - December 2023 - West Midlands