cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JasonCastro
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 

 

 

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
)

 

 

Something like:

SortByColumns(
"ID" && Status = "Approved"
Descending
)

 

2 REPLIES 2

@JasonCastro 

 

According to

SortByColumns - Power Apps - docs.microsoft.com

 

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.

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.

@JasonCastro 


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:

 

//pseudocode
Filter(YourTable,Status="Approved")

 

 

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:

 

//pseudocode
Filter(YourTable,If(SomeCheckbox.Value,Status="Approved",true))

 

 

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 

Helpful resources

Announcements
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)