cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Vega
New Member

Gallery filtering on the latest record

Hi All,

 

I have a SharePoint list that records the data loads between databases. This contains all the records for historic loads but I want to show the latest record for each job in a gallery.

 

I have the following fields :

 

Title - Name of the job

Start Time - Date/Time field

End Time - Date/Time field

Elapsed Time - Calc based on the Start and End Time

Rows Updated - Number

Status - Choice field

 

My logic in the gallery item was originally :

 

SortByColumns(Filter([@'SharePointListName'],StartsWith(Title,TextSearchBox1.Text)),"Title",If(SortDescending1,Descending,Ascending))

 

This returned all records, however i only need the latest record. The jobs dont always run on the same day so i need the max record i think and i need to apply a group by? These are the bits i'm not sure on. I have done the group by but it only returns the Title field : 

 

GroupBy(
SortByColumns(
Filter([@'SharePointListName'],StartsWith(Title,TextSearchBox1.Text)),
"Title",
If(SortDescending1,Descending,Ascending)),
"Title","Grouped")

 

How do i add the latest record fields (Start Time, End Time, Elapsed Time, Rows Updated, Status) to the gallery?

 

Thanks,

 

Matt

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @Vega ,

 

Could you tell me:

  • Do you want the table to be sorted in ascending order by Title field?  Look like my picture below:

v-xiaochen-msft_0-1606097906724.png

 

 

If so , please set the value of SortDescending1 to false .

In my code, the value of SortDescending1 is true. I sort the table in descending order.

v-xiaochen-msft_1-1606097906726.png

 

 

Please try the following code:

SortByColumns(

    Filter(

        ForAll(

            Distinct(

                SharePointListName,

                Title

            ),

            LookUp(

                SortByColumns(

                    SharePointListName,

                    "ID",

                    Descending

                ),

                Result = Title

            )

        ),

        StartsWith(

            Title,

            TextSearchBox1.Text

        )

    ),

    "Title",

    If(

        SortDescending1,                      //The value of ‘SortDescending1’ is false here.

       Descending,

        Ascending

    )

)

 

If my guess is wrong, please tell me your needs in more detail, and I will be happy to solve the problem for you.

 

Best Regards,

Wearsky

View solution in original post

4 REPLIES 4
v-xiaochen-msft
Community Support
Community Support

Hi @Vega ,

 

Could you tell me:

  1. What field is used to find the latest record?
  2. What is SortDescending1 in your formula?

 

I assume:

  1. Use ID field to find the latest record.
  2. The value in SortDescending1 is true.

 

If the above assumptions are true, the point is to use the sortbycolumns() function to sort the ID field from high to low, and then use lookup() function to get the latest record.

I've made a test for your reference:

 

1\ Show my data in list:

v-xiaochen-msft_0-1605863188445.png

 

 

2\ Add a gallery control to screen and set its Items property to:

SortByColumns(

    Filter(

        ForAll(

            Distinct(

                SharePointListName,

                Title

            ),

            LookUp(

                SortByColumns(

                    SharePointListName,

                    "ID",

                    Descending

                ),

                Result = Title

            )

        ),

        StartsWith(

            Title,

            TextSearchBox1.Text

        )

    ),

    "Title",

    If(

        SortDescending1,                      //The value of ‘SortDescending1’ is true here.

       Descending,

        Ascending

    )

)

 

3\ The result are as follow:

v-xiaochen-msft_1-1605863188447.png

 

v-xiaochen-msft_2-1605863188448.png

 

 

Best Regards,

Wearsky

Vega
New Member

Thanks so much for the response, i might not have been very clear but i only want to display the latest run for each job in the gallery. So, based on your data, it should look like :

Job 1 - Start Time : 05/11/2020

Job 2 - Start Time : 14/11/2020

 

Thanks,

Matt

Hi @Vega ,

 

Could you tell me:

  • Do you want the table to be sorted in ascending order by Title field?  Look like my picture below:

v-xiaochen-msft_0-1606097906724.png

 

 

If so , please set the value of SortDescending1 to false .

In my code, the value of SortDescending1 is true. I sort the table in descending order.

v-xiaochen-msft_1-1606097906726.png

 

 

Please try the following code:

SortByColumns(

    Filter(

        ForAll(

            Distinct(

                SharePointListName,

                Title

            ),

            LookUp(

                SortByColumns(

                    SharePointListName,

                    "ID",

                    Descending

                ),

                Result = Title

            )

        ),

        StartsWith(

            Title,

            TextSearchBox1.Text

        )

    ),

    "Title",

    If(

        SortDescending1,                      //The value of ‘SortDescending1’ is false here.

       Descending,

        Ascending

    )

)

 

If my guess is wrong, please tell me your needs in more detail, and I will be happy to solve the problem for you.

 

Best Regards,

Wearsky

View solution in original post

This is great! I 've actually sorted by the Start Time rather than the ID as in my POC example I have retro added records. But your thinking was correct. Once again, big thanks!!

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Apps Community Call

Monthly Power Apps Community Call

Did you miss the call?? Check out the Power Apps Community Call here!

secondImage

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Top Kudoed Authors
Users online (42,818)