Showing results for 
Search instead for 
Did you mean: 
Helper I
Helper I

Filter using SortByColumns with condition

I would like to change the search to bring the Status column where the most recent Status is equal to "Approved".
As it stands today, I'm bringing the latest ID, as can be seen at the end of the code 



        ) && (UNIDADES.Value = comboBoxUnidades.Selected.Title || comboBoxUnidades.Selected.Title = Blank())
        &&(comboBoxSearchProcessos.Selected.NOME_GERENCIA in PROCESSO_RESPONSAVEL.Value || comboBoxSearchProcessos.Selected.NOME_GERENCIA = Blank())



Something like:

"ID" && Status = "Approved"





According to

SortByColumns - Power Apps -


Syntax is as follows:

SortByColumnsTableColumnName1 [, SortOrder1ColumnName2SortOrder2, ... ] )

So you can try to sort by the Latest ID first, then by the Status in Ascending order, so you could do something like:


//pseudocode. Beware: semicolon for Power Apps list separator is being used, rather than a comma, in this example.






Note that I did not test the above, you may want to adjust it so it makes sense for you.


Although it might order it the way you want, you will still see the other statuses though, too. You probably can't filter inside the SortByColumns. You'll need to Filter this out in your original big formula somewhere, if you really only want "Approved" status and nothing else to show. I put Status Ascending for now as a possible way, because chances are, your other statuses in ABC order, are something with a letter after A - so the Approved ones might show first before the others if you do the above - so this might end up working for you as well.


In case that you are asking whether this filtering out of everything else except records where the Status = "Approved" can be done with SortByColumns. I am not aware of any way to do that.  The only way I know of, is that if you really want this, you'll need to put this in your Filter somewhere:





If you need to show Status="Approved" records, but to do this only done sometimes, and other times you still want it to show all the other Statuses, such as perhaps based on a checkbox, you should still be able do something like this fine:





So the answer is, @JasonCastro that you should be able to do what you want.

However, I am not aware of any way that you can do this:


//I do not think this is possible
    "ID" && Status = "Approved"
//I believe you can't do the above.



I believe you cannot do that, because SortByColumns, to my awareness, only sorts and does not perform any kind of filtering on the Table.


See if it helps @JasonCastro 

Helpful resources

Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (2,545)