cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PowerSäm
Continued Contributor
Continued Contributor

Sort requests by newest - How?

Halllo All,

I have built a gallery where all created requests are displayed. This sorts by itself somehow. But now, I want, that the latest requests are always displayed at the top, how can I achieve that? What do I have to change in the current code?
(See picture below)

 

If(varSortbyStatus;
    SortByColumns(
        Filter(
            AddColumns(
                colUrlaubReise; "StatusText";Status.Value
            );
        Erstelltvon.Email = User().Email);
        "StatusText"; ["Beantragt"; "Genehmigt";"Abgelehnt";"Storniert"]);

        Filter(colUrlaubReise;
            If(varFilter = "Alle"; true; Status.Value=varFilter);
            Erstelltvon.Email = User().Email)
)

 

PowerSm_0-1652702214055.png

 

Thanks in advance!

8 REPLIES 8
BCBuizer
Super User
Super User

Hi @PowerSäm ,

 

Please give the below a go. Unfortunately I don't have time to test it.

SortByColumns(
    Filter(
        AddColumns(
            colUrlaubReise; "StatusText";Status.Value
        );
        Erstelltvon.Email = User().Email);
		
    If(varSortbyStatus; "StatusText"; ["Beantragt"; "Genehmigt";"Abgelehnt";"Storniert"]);
	Erstelldatum; Descending
)

 Ps. I hope I got the translation for the 'Created' column in Sharepoint correct: Erstelldatum

PowerSäm
Continued Contributor
Continued Contributor

Hello @BCBuizer ,

thank you for your quick reply.

 

Do you mean like this? Unfortunately it shows me an error in the IF statement. What can be the reason for this?

I had to change the order, first descending then the Erstelldatum ("Erstelltam").

PowerSm_0-1652705347788.png

 

Do you have any idea?

 

Thank you

BCBuizer
Super User
Super User

Hi @PowerSäm,

 

I was trying something to combine the two filters, but that doesn't seem to work. You'll probably have better luck with the below where both filters are completely separated and where the Erstelltam column has been added:

If(varSortbyStatus;
	SortByColumns(
		Filter(
			AddColumns(
				colUrlaubReise; 
				"StatusText";
				Status.Value
			);
			Erstelltvon.Email = User().Email
		);
		"StatusText"; ["Beantragt"; "Genehmigt";"Abgelehnt";"Storniert"];
		"Erstelltam"; Descending
	);
	SortByColumns(
		Filter(
			colUrlaubReise;
			Erstelltvon.Email = User().Email
		);
	"Erstelltam"; Descending
	)
)

 

PowerSäm
Continued Contributor
Continued Contributor

Thank you for your reply, @BCBuizer 

.

Unfortunately, it told me that the SortbyColumn function has invalid arguments (see image below).

 

Why? What can be the reason for that?

 

Thank you very much in advance.

 

PowerSm_1-1652778665598.png

 

 

PowerSm_0-1652778644206.png

 

BCBuizer
Super User
Super User

Hi @PowerSäm ,

 

Not sure what is happening here is the sorting order for StatusText is copied lierally from your opening post where it doesn't produce any errors. Have any changes been made to the Status Column?

PowerSäm
Continued Contributor
Continued Contributor

Hello and thank you so much for your reply, @BCBuizer .

 

I think the problem is that we forgot the ELSE function. In the original code is the following formula (see pic below).

PowerSm_0-1652954961558.png

But now this has been forgotten. Can it be because of this?

 

Thank you very much in advance!

Hi @PowerSäm,

 

There is an Else statement in there, but I see it is missing a line. Unfortunately this is not the part that is causing the error:

BCBuizer_0-1653048918031.png

 

For completeness, here's the code with the missing line included:

If(varSortbyStatus;
	SortByColumns(
		Filter(
			AddColumns(
				colUrlaubReise; 
				"StatusText";
				Status.Value
			);
			Erstelltvon.Email = User().Email
		);
		"StatusText"; ["Beantragt"; "Genehmigt";"Abgelehnt";"Storniert"];
		"Erstelltam"; Descending
	);
	SortByColumns(
		Filter(
			colUrlaubReise;
			If(varFilter = "Alle"; true; Status.Value=varFilter);
			Erstelltvon.Email = User().Email
		);
	"Erstelltam"; Descending
	)
)

 

For testing purposes, can you try replacing the sort order for the StatusText to Descending to see if that makes the error go away?:

If(varSortbyStatus;
	SortByColumns(
		Filter(
			AddColumns(
				colUrlaubReise; 
				"StatusText";
				Status.Value
			);
			Erstelltvon.Email = User().Email
		);
		"StatusText"; Descending;
		"Erstelltam"; Descending
	);
	SortByColumns(
		Filter(
			colUrlaubReise;
			If(varFilter = "Alle"; true; Status.Value=varFilter);
			Erstelltvon.Email = User().Email
		);
	"Erstelltam"; Descending
	)
)
PowerSäm
Continued Contributor
Continued Contributor

Hi @BCBuizer and thank you sooo much for your reply!

 

Sorry for the late reply, but lately I had not managed to be active here on the community page, so I saw your answer only now.
Thank you, your second solution worked great, just as I was looking for!

 

But now I have only another small problem, which worked before...

If I click on the button "Kategorie", then all requests should be attracted, but by application type, means first of all all leave applications and then all business trip applications (See image below).

PowerSm_1-1656598642819.png

 

 

I have already stored in a column in Sharepoint after each request what type it is. (See image below)

PowerSm_2-1656598750410.png        PowerSm_3-1656598813810.png

 

How can I build now the button so that it first shows all requests with "request type = "leave""(In german "Urlaub") and then "request type= "business trip""(In german "Dienstreise")?

 

The button now is just built up as follows (See image below).

PowerSm_0-1656598568345.png

 

Regarding the gallery, you already know how this one is build.

 

Thank you so much! You are a great help. Thank you very much!

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (3,909)