cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Livearus
Helper I
Helper I

Filter the gallery by the latest date, or by DatePicker

Hello everybody,

 

can someone tell me what I am doing wrong with the following example?

 

If(
    DatePicker3.SelectedDate >= 1;
    Sort(
        Filter(
            'Reports';
            DatePicker3.SelectedDate = 'ReportTime'
        );    
    Descending
    );
    'Reports'
)

 

There is a SharePoint list with a "ReportTime" column. New reports are created every day so that the bottom entry in the SharePoint list is the most current.

 

In Power Apps I want to query the SharePoint list and filter the returned result by the latest date.

 

So far it looks like the entries are being displayed to me, but the filtering doesn't really work. In the gallery, the oldest entry is at the top, as well as from SharePoint.

 

As if that wasn't enough. There is a DatePicker in the APP. If the user selects a specific date, only the reports with the selected date should be queried or, if no date is selected, then preferably only the last 30 entries from the list (filtered according to the latest "ReportTime").

 

It works, but unfortunately without filtering.

 

regards

Livearus

1 ACCEPTED SOLUTION

Accepted Solutions

@Livearus Try this,

If(IsBlank(DatePicker3.SelectedDate),
	Sort(LastN(Reports;30);'ReportTime';Descending),
	Filter(Reports;DatePicker3.SelectedDate = 'ReportTime')
)

View solution in original post

6 REPLIES 6
CNT
Super User
Super User

@Livearus date picker returns something of type Date Value. Do you cannot compare it with a number. You have to compare it with another DateValue like,

If(date picker. SelectedDate=Today()....

 

Okay, I think the following features are needed to achieve my goal. But how is the query compared. I have to admit that I have a bit of a problem with the "IF condition", which will probably apply here.

 

LastN(Reports;30)
Filter(Reports;DatePicker3.SelectedDate = 'ReportTime')
Sort(Reports;'ReportTime';Descending)

 

First, if the DatePicker3 is not selected, the "Sort" function is executed. The reports are loaded in the desired order.

 

But only the last 30 may be displayed, instead the "LastN" function.

 

But if DatePicker3 is selected, the "Fiter" function is carried out.

 

Can you help me with this?

 

The functions on their own already lead to the desired result, just not in combination with one another.

 

regards

Livearus

@Livearus Try this,

If(IsBlank(DatePicker3.SelectedDate),
	Sort(LastN(Reports;30);'ReportTime';Descending),
	Filter(Reports;DatePicker3.SelectedDate = 'ReportTime')
)

View solution in original post

Hey

 

sorry about the late reply. Except for one small thing, your suggested solution was correct. Before the "isBlank" function a "!" Had to be added. Guess to check whether the return value is "not empty" instead of checking that it is "empty"?

 

If(!IsBlank(DatePicker3.SelectedDate),
	Sort(LastN(Reports;30);'ReportTime';Descending),
	Filter(Reports;DatePicker3.SelectedDate = 'ReportTime')
)

 

regards

Livearus

@Livearus Glad you got it right!

Livearus
Helper I
Helper I

Hmm

 

I guess I wasn't right after all. "Kneeling and Confusion". I should have tested whether everything works even after selecting a date. Unfortunately not.

 

The "!" then, contrary to my assumption, does not have the logic to check whether "not empty" instead of "empty". Rather, it simply removes the function of "IsBlank".

 

Do you or anyone else have another approach to the problem?

 

regards

Livearus

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (1,311)