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
SortByColumns( Filter( TBL_INFORME_GERENCIAL; StartsWith( 'PTM-RESERVA-REMESSA-RT'; searchTxt.Text ) && (UNIDADES.Value = comboBoxUnidades.Selected.Title || comboBoxUnidades.Selected.Title = Blank()) &&(comboBoxSearchProcessos.Selected.NOME_GERENCIA in PROCESSO_RESPONSAVEL.Value || comboBoxSearchProcessos.Selected.NOME_GERENCIA = Blank()) ); "ID"; Descending )
SortByColumns( "ID" && Status = "Approved" Descending )
Syntax is as follows:
SortByColumns( Table, ColumnName1 [, SortOrder1, ColumnName2, SortOrder2, ... ] )
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. SortByColumns ( YourBigFilterFormula ;"ID" ;Descending ;"Status" ;Ascending )
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 SortByColumns ( SomeTable "ID" && Status = "Approved" Descending ) //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