cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ljkeefe
Helper I
Helper I

How to get the nth weekday for a month?

I've made a bit of progress in getting the 2nd Tuesday of the month, the 1st & 3rd Tuesday, and 2nd & 4th Tuesday. I found the formulas I've pieced together to sort of work. 

I have a date picker for Committee A and another for Committee B which is held every 2nd Tuesday of the month. I'd like for the date populated in Committee A field to auto-populate Committee B with the second if the Tuesday month of the date in Committee A has not passed the 2nd Tuesday of the current month if it has, I'd like for it to populate Committee B field with the 2nd Tuesday in the upcoming month. 

For the 2nd Tuesday of the month, I have the following Committee B DefaultDate:

With({FirstOfMonth:Date(CommitteeADatepicker.selecteddate),DayOfWeek:3,N:2},DateAdd(FirstOfMonth,(N * 7) - Weekday(DateAdd(FirstOfMonth,7DayOfWeek))))

This formula works only if the date in Committee A is BEFORE the 2nd Tuesday of the month, if it isn't, it just moves the date in Committee B field out a week.

I figure once I can get the 2nd Tuesday field figured out, it should relatively the same for the committees that are on the 1st and 3rd Tuesday of the month.

Thank you in advance for your help!

1 ACCEPTED SOLUTION

Accepted Solutions
timl
Super User
Super User

Hi @ljkeefe 

You can do this by adding an If statement - if the first Tuesday of the current month is greater than the date selected in CommitteeADatePicker, you would calculate the first Tuesday of the following month by adding a month.
This is the formula you would use.

With({FirstOfMonth:Date(Year(CommitteeADatepicker.SelectedDate),
                        Month(CommitteeADatepicker.SelectedDate),1),
      DayOfWeek:3,
      N:2
     },
     With({FirstTuesday:DateAdd(FirstOfMonth,
             (N * 7) - Weekday(DateAdd(FirstOfMonth,7-DayOfWeek))
     )},
	 If(CommitteeADatepicker.SelectedDate > FirstTuesday,
        DateAdd(DateAdd(FirstOfMonth, 1, Months),
             (N * 7) - Weekday(DateAdd(DateAdd(FirstOfMonth, 1, Months),7-DayOfWeek))
        ),
        FirstTuesday
     )
  ) 
) 

 

View solution in original post

3 REPLIES 3
timl
Super User
Super User

Hi @ljkeefe 

You can do this by adding an If statement - if the first Tuesday of the current month is greater than the date selected in CommitteeADatePicker, you would calculate the first Tuesday of the following month by adding a month.
This is the formula you would use.

With({FirstOfMonth:Date(Year(CommitteeADatepicker.SelectedDate),
                        Month(CommitteeADatepicker.SelectedDate),1),
      DayOfWeek:3,
      N:2
     },
     With({FirstTuesday:DateAdd(FirstOfMonth,
             (N * 7) - Weekday(DateAdd(FirstOfMonth,7-DayOfWeek))
     )},
	 If(CommitteeADatepicker.SelectedDate > FirstTuesday,
        DateAdd(DateAdd(FirstOfMonth, 1, Months),
             (N * 7) - Weekday(DateAdd(DateAdd(FirstOfMonth, 1, Months),7-DayOfWeek))
        ),
        FirstTuesday
     )
  ) 
) 

 

View solution in original post

Thanks, @timl ! That works. I thought that I would be ok taking that syntax and modifying it for the 1st Tuesday and 3rd Tuesday of the month but it's not working. This is pretty similar to the previous scenario of the date computed in Committee B field is great than the 1st and 3rd Tuesday of the month, then it calculates to the first Tuesday of the next month. I'm pretty sure it's my IF statement.  Here's how I modified it:

With({FirstofMOnth:Date(Year(CommitteeBDatePicker.SelectedDate),Month(CommitteeBDatePicker.SelectedDate),1),DayOfWeek:3,N:1},With({FirstTuesday:DateAdd(FirstofMOnth,(N*7)-Weekday(DateAdd(FirstofMOnth,7-DayOfWeek)},With({ThirdTuesday:DateAdd(FirstofMOnth,(2*N*7)-Weekday(DateAdd(FirstofMOnth,7-DayOfWeek)))},
If(CommitteeBDatePicker.SelectedDate>=FirstTuesday,ThirdTuesday,CommitteeBDatePicker.SelectedDate>ThirdTuesday,(DateAdd(DateAdd(FirstofMOnth,1,Months,(N*7)-Weekday(DateAdd(FirstofMOnth,7-DayOfWeek)),ThirdTuesday))))

 

Thank you for your help. I'm still relatively new to Power Apps, about four months now. It's amazing how much there is to learn. Thank you again.

 

Never mind, I got it!

Thanks!!

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

secondImage

Power Apps Community Call

Please join us on Wednesday, October 20th, at 8a PDT. Come and learn from our amazing speakers!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (1,606)