Hi! So i'm currently trying to establish a relationship between two dropdowns: Month and Week and Date Picker (I'm using modern controls)
CONTEXT
Here's what it needs to do. If I choose a month, lets say "May" the dropdown for Week should automatically populate based on the weeks for May (Week 19 - Week 22). Should look like this in the Week dropdown:
- Week 19
- Week 20
- Week 21
- Week 22
Ideally:
- Week 19 (Monday - Saturday dates for the week) and so on
ISSUE
Now here is my code for the OnChange property in my month dropdown. The thing is, it's working but the items listed in the Week are random numbers instead of Week 19 - 20 when i choose the month May. Can I ask for help on what should change for this code or like initialize first. Thank you!
If(!IsBlank(inp1_ANMonth.Selected.MonthNumber),
With(
{
FirstDayOfMonth: Date(Year(Today()), inp1_ANMonth.Selected.MonthNumber, 1)
},
With(
{
FirstDayOfWeek: Weekday(FirstDayOfMonth, StartOfWeek.Monday)
},
ClearCollect(WeeksForSelectedMonth,
Table(
{WeekStart: FirstDayOfMonth - FirstDayOfWeek + 1, WeekNumber: "Week 1"},
{WeekStart: DateAdd(FirstDayOfMonth, 7 - FirstDayOfWeek), WeekNumber: "Week 2"},
{WeekStart: DateAdd(FirstDayOfMonth, 14 - FirstDayOfWeek), WeekNumber: "Week 3"},
{WeekStart: DateAdd(FirstDayOfMonth, 21 - FirstDayOfWeek), WeekNumber: "Week 4"},
// Add more records here if the month has more than 4 weeks
// The following is an example for a fifth week; adjust as necessary
{WeekStart: DateAdd(FirstDayOfMonth, 28 - FirstDayOfWeek), WeekNumber: "Week 5"}
// Ensure the last week doesn't exceed the month's days
)
)
)
),
Clear(WeeksForSelectedMonth) // Clear the collection if the month is blank
)

Report
All responses (
Answers (