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

One day, one of my colleagues asked me if we could filter the Power Apps gallery by the previous five weeks to get all the filtered data. Yes, we can achieve it by using some Power Apps functions like Today(), Weekday(), etc.

In this Power Apps tutorial, I will discuss how to filter Power Apps gallery by week, such as current week, next week, and previous week. Additionally, we will see how to filter the gallery in Power Apps by the next N weeks and previous N weeks with a few examples.

Filter Power Apps 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 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
Power Apps Filter a Gallery By Current 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
Add JSLink in Task List View in SharePoint
  • 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 take the same SharePoint 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 following 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], as shown 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 following ‘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 &#039;N&#039; 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. 7 is the number of weekdays, and 4 is the next number of weeks.

Refer to the below screenshot:

How to Filter Power Apps Gallery By Next &#039;N&#039; 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 &#039;N&#039; 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 SharePoint 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 use the same SharePoint list [Expense Tracker] for this example. Power Apps has a Gallery control. This gallery displays each record from the SharePoint list based on the last two weeks.
Power Apps Filter Gallery By Previous &#039;N&#039; 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,

Today()—(7*2) = Today () function helps to get the current date. 7 is the number of weekdays, and 2 is the last number of weeks.

Power Apps Filter Gallery By Last &#039;N&#039; Weeks
  • Save, Publish, and Preview the app. The gallery will display the filtered records, i.e., [Last Two Week’s Records], as shown below.
Power Apps Gallery Filter By Previous &#039;N&#039; 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:

>

Build a High-Performance Project Management Site in SharePoint Online

User registration Power Apps canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App

Power Platform Tutorial FREE PDF Download

FREE Power Platform Tutorial PDF

Download 135 Pages FREE PDF on Microsoft Power Platform Tutorial. Learn Now…