Power Apps Sort Gallery By Day [With Examples]

This Power Apps tutorial will explain how to sort a Power Apps gallery by day. Like, how to sort a Power Apps gallery by the current day and sorting a Power Apps gallery by the next day, and how to sort a Power Apps gallery by the next ‘N’ days.

In the last, I will cover sorting a Power Apps gallery by the previous day and how to sort a Power Apps gallery by the last ‘N’ days.

Power Apps Sort Gallery By Day [Current Day]

Here, we will discuss how to sort a Power Apps gallery by the current day with a simple example.

Example:

I have a SharePoint Online list, i.e., [Product Details] and this list contains the below fields.

Column NameData Type
Product NameDefault single line of text
ManufacturerChoice
PriceCurrency
Purchase DateDate and time

power apps sort gallery by days

Now, I want to sort the Power Apps gallery records [Ascending] from the SharePoint Online list, as in the screenshot below.

sort power apps gallery by today

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

1. Open Power Apps -> Create a Blank canvas app and connect it to the SharePoint list as shown below.

power apps sort gallery control by days

2. Then, insert a Gallery control [gal_Products] and set its Items property to the code below.

Items = With(
    {
        StartDate: Today(),
        EndDate: Today() + 1
    },
    SortByColumns(
        Filter(
            'Product Details',
            'Purchase Date' >= StartDate,
            'Purchase Date' < EndDate
        ),
        "Title",
        SortOrder.Ascending
    )
)

Where,

  • With() = This function can help us to evaluate a formula for a single record
  • StartDate, EndDate = Power Apps scope variables
  • Today() = Power Apps Today() helps to get the current date
  • ‘Product Details’ = SharePoint Online list
  • ‘Purchase Date’ = SharePoint date and time field
  • “Title” = SharePoint text field
sort power apps gallery by days

3. Save, Publish, and Preview the app. The Power Apps gallery sort and display each record from a SharePoint list as in the screenshot below.

sort power apps gallery by current day

This is how to sort a Power Apps gallery by current day/ today.

Power Apps Sort Gallery By Next Day

Next, we will see how to sort a Power Apps gallery by the next day.

Example:

I will also take the same SharePoint online list [Product Details] for this example. In Power Apps, there is a gallery control. This gallery sort and display each record from a SharePoint list based on the next day [Descending Order] like below.

power apps sort gallery by tomorrow

To do so, follow the steps.

1. On the Power Apps Screen -> Insert a Power Apps gallery and set its Items property as:

Items = With(
    {
        StartDate: Today(),
        EndDate: Today() + 1
    },
    Sort(
        Filter(
            'Product Details',
            'Purchase Date' > StartDate,
            'Purchase Date' <= EndDate
        ),
        Title,
        SortOrder.Descending
    )
)

Where,

  • StartDate, EndDate = Power Apps Scope Variables
  • Today() + 1 = Tomorrow’s Date
how to sort power apps gallery by next day

2. Save, Publish, and Preview the app. The gallery sort and display each record from a SharePoint list based on the tomorrow as shown below.

sort power apps gallery by next day

This is how to sort a Power Apps gallery by the next day.

Power Apps Sort Gallery By Next ‘N’ Days

Similarly, we will discuss how to sort a Power Apps gallery by the next 2 days.

In this example, I will also take the above SharePoint Online list and I want to sort the Power Apps gallery records based on the next two days. I have used the code below in the Gallery’s Items property.

Items = With(
    {
        StartDate: Today(),
        EndDate: Today() + 2              // You can also change the number of days
    },
    SortByColumns(
        Filter(
            'Product Details',
            'Purchase Date' >= StartDate,
            'Purchase Date' <= EndDate
        ),
        "Title",
        SortOrder.Ascending
    )
)

Where,

  • Today() + 2 = Today() function helps to get the current date. And 2 is the number of weekdays.
how to sort power apps gallery by next day

Save, publish, and Preview the app. The gallery will sort and display each record from the SharePoint list based on the next 2 days as in the screenshot below.

power apps sort gallery by upcoming N days

This is how to sort a Power Apps gallery by the next two days.

Power Apps Sort Gallery by Last Day

Let’s see how to sort a Power Apps gallery by the last day. Here, I will also take the same SharePoint list for this example.

In Power Apps, there is a Gallery control. This gallery will sort and display SharePoint list records based on yesterday. For that, follow the below Gallery’s Items property code:

Items = With(
    {
        StartDate: Today() - 1,
        EndDate: Today()
    },
    SortByColumns(
        Filter(
            'Product Details',
            'Purchase Date' >= StartDate,
            'Purchase Date' < EndDate
        ),
        "Title",
        SortOrder.Ascending
    )
)

Where,

  • Today()-1 = Yesterday’s Date
how to sort power apps gallery by yesterday

Now, whenever the user opens a gallery control, it will sort and display each record from a SharePoint list based on the last day, as shown below.

power apps sort gallery by yesterday

This is how we can sort a Power Apps gallery by yesterday/last day.

Power Apps Sort Gallery By Last ‘N’ Days

I will show you how to sort a Power Apps gallery by the last 3 days.

Example:

I will also use the same SharePoint Online list [Product Details] for this example. In Power Apps, there is a Gallery control. This gallery will sort and display each record from a SharePoint list based on the last 3 days.

For that, I have used the below-mentioned code in the Gallery Items property:

Items = SortByColumns(
    Filter(
        'Product Details',
        'Purchase Date' >= DateAdd(
            Today(),
            -3,                                                       // You can also change the number of days
            TimeUnit.Days
        )
    ),
    "Title",
    SortOrder.Ascending
)

Where,

  • ‘Product Details’ = SharePoint list
  • DateAdd() = This function adds a number of units to a Date/Time column
  • -3 = Number of Previous Days
how to sort power apps gallery by last N days

Once your app is ready, Save, Publish, and Preview the app. The gallery will sort and display SharePoint list records based on the last 3 days, as in the screenshot below.

power apps sort gallery by previous N days

This is all about sorting a Power Apps gallery by the last 3 days.

Conclusion

I trust this Microsoft Power Apps tutorial explained everything about how to sort a Power Apps gallery by day. Like:

  • Power App sort gallery by current day
  • How to sort a Power Apps gallery by the next day
  • Sorting a Power Apps gallery by the last day
  • How to sort a Power Apps gallery by next ‘N’ days
  • Working with Power Apps sort a gallery by the last ‘N’ days

You may also like:

>