Power Apps Filter Gallery By Week [Current, Next, Next N, Previous, Previous N]

Do you know how to filter a Power Apps gallery by week? No worries!

This Power Apps tutorial explains everything about the Power Apps filter gallery by week like:

  • How to filter Power Apps gallery by current week
  • Filter Power Apps gallery by next week
  • Working with Power Apps filter gallery by next ‘N’ weeks
  • How to filter Power Apps gallery by last week
  • Power Apps filter gallery by previous ‘N’ weeks

Power Apps Filter Gallery By Week [Current Week]

Here, I will show you how to filter a Power Apps gallery by the current week.

Example:

  • I have a SharePoint Online List named “Expense Tracker“. This list contains the below fields.
Column NameData Type
ItemThis is a Title column with a single line of text. I just renamed it to “Item”
CategoryChoice
Payment DateDate and time
AmountNumber
Power Apps Filter Gallery By Week
  • In Power Apps, there is a Gallery control. This gallery displays each record from the SharePoint list based on the current week.
Power Apps Filter a Gallery By Current Week

To achieve the above example, follow the below-mentioned steps. Such as:

Power Apps Filter Gallery By This Week
  • Insert a Gallery control [gal_CurrentWeekExpenses] and set its Items property as:
Items = With(
    {
        StartDate: Today() - (Weekday(
            Today(),
            StartOfWeek.Sunday
        )) + 1,
        EndDate: DateAdd(
            Today(),
            (7 - Weekday(
                Today(),
                StartOfWeek.Sunday
            )),
            TimeUnit.Days
        )
    },
    Filter(
        'Expense Tracker',
        'Payment Date' >= StartDate,
        'Payment Date' <= EndDate
    )
)

Where,

  1. StartDate, EndDate = Power Apps Scope Variables
  2. Today() = Power Apps Today() helps to get the current date
  3. ‘Expense Tracker’ = SharePoint Online List
  4. ‘Payment Date’ = SharePoint Date Field
Power Apps Gallery Filter By Current Week
  • SavePublish, and Preview the app. The gallery will display the filtered records, i.e., [This Week’s Records], as in the screenshot below.
Power Apps Gallery Filter By Using This Week

This is how to filter a Power Apps gallery by the current week.

Power Apps Filter Gallery By Next Week

Next, we will see how to filter a Power Apps gallery by next week.

Example:

  • I will also take the same SharePoint Online list [Expense Tracker] for this example.
  • In Power Apps, there is a Horizontal Gallery control. This gallery displays each record from the SharePoint list based on the next or upcoming week.
Power Apps Gallery Filter By Next Week

To work around this example, follow the below steps. Such as:

  • On the Power Apps Screen -> Insert a Gallery control and set its Items property as:
Items = With(
    {
        StartDate: Today() - (Weekday(
            Today(),
            StartOfWeek.Sunday
        )) + 7,
        EndDate: DateAdd(
            Today(),
            (7 - Weekday(
                Today(),
                StartOfWeek.Sunday
            ))+7,
            TimeUnit.Days
        )
    },
    Filter(
        'Expense Tracker',
        'Payment Date' > StartDate,
        'Payment Date' <= EndDate
    )
)

Where,

  1. Today() = Power Apps Today() helps to get the current date
  2. Weekday() = This function returns a number representing the day of the week depending on the start date of the week
  3. StartOfWeek.Sunday = Start date of the week
  4. 7 = It is the number of days in a week
  5. TimeUnit.Days = This time units can evaluate the number of days in a week

Refer to the image below:

Power Apps Filter Gallery By Upcoming Week
  • Save, Publish, and Preview the app. The gallery will display the filtered records, i.e., [Next Week’s Recors] like below.
Power Apps Filter Gallery By Next Week

This is how to filter a Power Apps gallery by the next week.

Power Apps Filter Gallery By Next ‘N’ Weeks

Let’s see how to filter the Power Apps gallery by the next ‘N’ weeks.

Example:

  • I will take the same SharePoint Online list [Expense Tracker] for this example.
  • In Power Apps, there is a Vertical Gallery control. This gallery filters and displays each record from the SharePoint list based on the next/upcoming four weeks.
Power Apps Filter Gallery By Next 'N' Weeks

To do so, follow the below-mentioned steps.

  • On the Power Apps Screen -> Insert a Gallery control and set its Items property to the code below.
Items = With(
    {
        StartDate: Today(),
        EndDate: Today() + (7*4)      // You can also change the number of weeks
    },
    Filter(
        'Expense Tracker',
        'Payment Date' >= StartDate,
        'Payment Date' <= EndDate
    )
)

Where,

  1. Today() + (7*4) = Today() function helps to get the current date. And, 7 is the number of weekdays, and 4 means the next number of weeks.

Refer to the below screenshot:

How to Filter Power Apps Gallery By Next 'N' Weeks
  • Save, Publish, and Preview the app. The gallery will display the filtered records, i.e., [Next 4 Week’s Records], as in the screenshot below.
Power Apps Gallery Filter By Next 'N' Weeks

This is all about the Power Apps filter gallery by the next ‘N’ weeks.

Power Apps Filter Gallery By Previous Week

Similarly, here we will see how to filter a Power Apps gallery by the previous week.

Example:

  • I will take the same above SharePoint Online list [Expense Tracker] for this example.
  • In Power Apps, there is a Vertical Gallery control. This gallery displays each record from the SharePoint list based on the last or previous week.
Power Apps Filter Gallery By Previous Week

To achieve the above example, follow the below steps. Such as:

  • On the Power Apps Screen -> Insert a Gallery control and set its Items property as:
Items = With(
    {
        StartDate: Today()-(Weekday(Today(), StartOfWeek.Sunday))-7,
        EndDate: DateAdd(Today(),(7-Weekday(Today(), StartOfWeek.Sunday))-7,TimeUnit.Days)
    },
    Filter(
        'Expense Tracker',
        'Payment Date' > StartDate,
        'Payment Date' <= EndDate
    )
)

Where,

  1. Today(), StartOfWeek.Sunday))-7 = Today () function helps to get the current date. And, -7 is for the last week

Refer to the below image:

Power Apps Filter Gallery By Last Week
  • Save, Publish, and Preview the app. The gallery will display the filtered records, i.e., [Last Week’s Records], as shown below.
Power Apps Gallery Filter By Previous Week

This is how to filter a Power Apps gallery by the previous week.

Power Apps Filter Gallery By Previous ‘N’ Weeks

Finally, I will show you how to filter a Power Apps gallery by previous ‘N’ weeks.

Example:

  • I will also take the same SharePoint Online list [Expense Tracker] for this example.
  • In Power Apps, there is a Gallery control. This gallery displays each record from the SharePoint list based on the last/previous two weeks.
Power Apps Filter Gallery By Previous 'N' Weeks

To work around this example, follow the below steps.

  • On the Power Apps Screen -> Insert a Gallery control and set its Items property code like below.
Items = With(
    {
        StartDate: Today()- (7*2),    // You can also change the number of weeks
        EndDate: Today()
    },
    Filter(
        'Expense Tracker',
        'Payment Date' > StartDate,
        'Payment Date' <= EndDate
    )
)

Where,

  1. Today()- (7*2) = Today () function helps to get the current date. And, 7 is the number of weekdays and 2 means the last number of weeks.
Power Apps Filter Gallery By Last 'N' Weeks
  • Save, Publish, and Preview the app. The gallery will display the filtered records, i.e., [Last Two Week’s Records] like below.
Power Apps Gallery Filter By Previous 'N' Weeks

This is how to filter a Power Apps gallery by the last ‘N’ weeks.

Conclusion

I have explained in detail the Power Apps filter gallery by week.

I have also discussed the Power Apps filter gallery by the current week and how to filter a Power Apps gallery by the last week.

In the last, I have covered the Power Apps gallery by the next ‘N’ weeks and how to filter a Power Apps gallery by the previous ‘N’ weeks.

Additionally, you may like some more Power Apps tutorials: