Filtering Collections for events this week.
Recently building a calendar control in Power Apps I wanted to show events for the selected week.
Luckily it’s fairly easy to calculate thanks to the Weekday
function.
To calculate the start date of the week:
This assumes our week starts on a Sunday, you can add which ever day you want. Saturday or Monday for example.
DateAdd(_dateSelected,-Weekday(_dateSelected,Sunday) + 1,Days)
Then to find the end of the week:
DateAdd(_dateSelected,-Weekday(_dateSelected,Sunday) + 7,Days)
So now we have the start of the week date and the end of the week date we can use these in our filter.
SortByColumns(
Filter(
MyCalendarEvents,
Start > DateAdd( _dateSelected,-Weekday(_dateSelected,Sunday) + 1,Days) &&
Start < DateAdd( _dateSelected,-Weekday(_dateSelected,Sunday) + 7,Days)
),
"Start"
)
What’s your Reaction?
+1
+1
+1
+1
+1
+1
+1