web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Apps
Answered

sort order

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi all 

so, i have the button1 onselect

Set(
varsorteia;
"overal"
) & Set(
sortdirection;
If(
sortdirection = Ascending;
Descending;
Ascending
)
)
 
and a datatable1 with
"overal";
If(
!IsBlank(Dropdown1.Selected.Result);//fazfiltro = "1";
Sort(
Filter(
colecaotudo;
ID > 1;//not list configuration line
Dropdown1.Selected.Result in Group.Value;
If(
!IsBlank(planned.SelectedDate) && Len(TextInput2.Text) >= 0;
'Planned to' <= planned.SelectedDate + 1 And (TextInput2.Text in Title Or TextInput2.Text in 'Objective(s)' Or TextInput2.Text in Stage.Value Or TextInput2.Text in 'DBS Lead'.DisplayName Or TextInput2.Text in 'Function Lead'.DisplayName Or TextInput2.Text in 'Planned to' Or TextInput2.Text in Function.Value Or TextInput2.Text in Group.Value)
) Or If(
!IsBlank(FunctionLeadFilter.Selected.Result) && Len(TextInput2.Text) >= 0;
FunctionLeadFilter.Selected.Result in 'Function Lead'.DisplayName And (TextInput2.Text in Title Or TextInput2.Text in 'Objective(s)' Or TextInput2.Text in Stage.Value Or TextInput2.Text in 'DBS Lead'.DisplayName Or TextInput2.Text in 'Function Lead'.DisplayName Or TextInput2.Text in 'Planned to' Or TextInput2.Text in Function.Value Or TextInput2.Text in Group.Value)
) Or If(
!IsBlank(Stage.Value) && Len(TextInput2.Text) >= 0;
Stage.Value in StageFilter.Selected.Result And (TextInput2.Text in Title Or TextInput2.Text in 'Objective(s)' Or TextInput2.Text in Stage.Value Or TextInput2.Text in 'DBS Lead'.DisplayName Or TextInput2.Text in 'Function Lead'.DisplayName Or TextInput2.Text in 'Planned to' Or TextInput2.Text in Function.Value Or TextInput2.Text in Group.Value)
) Or If(
!IsBlank(DBSLeadFilter.Selected.Result) && Len(TextInput2.Text) >= 0;
DBSLeadFilter.Selected.Result in 'DBS Lead'.DisplayName And (TextInput2.Text in Title Or TextInput2.Text in 'Objective(s)' Or TextInput2.Text in Stage.Value Or TextInput2.Text in 'DBS Lead'.DisplayName Or TextInput2.Text in 'Function Lead'.DisplayName Or TextInput2.Text in 'Planned to' Or TextInput2.Text in Function.Value Or TextInput2.Text in Group.Value)
) Or If(
!IsBlank(Function.Value) && Len(TextInput2.Text) >= 0;
Function.Value in FunctionFilter.Selected.Result And (TextInput2.Text in Title Or TextInput2.Text in 'Objective(s)' Or TextInput2.Text in Stage.Value Or TextInput2.Text in 'DBS Lead'.DisplayName Or TextInput2.Text in 'Function Lead'.DisplayName Or TextInput2.Text in 'Planned to' Or TextInput2.Text in Function.Value Or TextInput2.Text in Group.Value)
)
);
Overal.Value;
sortdirection
);
Sort(
Filter(
colecaotudo;
ID > 1;//not list configuration line
//Group.Value = filtragrupo;
If(
Len(TextInput2.Text) >= 0;
TextInput2.Text in Title Or TextInput2.Text in 'Objective(s)' Or TextInput2.Text in Stage.Value Or TextInput2.Text in 'DBS Lead'.DisplayName Or TextInput2.Text in 'Function Lead'.DisplayName Or TextInput2.Text in 'Planned to' Or TextInput2.Text in Function.Value Or TextInput2.Text in Group.Value
)
);
Overal.Value;
sortdirection
)
)
 
My Overal  possible values is "Green" "Yelow" "Red"
what i want is order my datatable on this column and in a click of the button1 firstly in this order  "Green" "Yelow" "Red"
second click  "Yelow" "Green" "Red"
third click  "Red""Yelow" "Green"
 
to simplify i want do sort a column in a personalized order, not only asc or desc. i want put on firstly the records with z and after asc.
 
how i do this?
Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Anonymous 

    Are you stating that you want personalized search capabilities...but I am confused that you say that the press of a button gives you three different sort selections.  Is this to say that the user would click on a button to change the order of the colors and then there would be a directional icon (or something) to change the order from ascending to descending and back?  Would that apply then to all the colors or are you wanting individual orders for individual colors?

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    no no .. in the same button change the sort..

    first click sort green yelow red,

    second click yelow red green

    third click red green yelow

     

  • MH-02091453-0 Profile Picture
    125 on at

     A good video for custom sorting:

    Power Apps SortByColumns and Sort function with a custom sort order - Bing video

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Anonymous 

    Yes, but you are mentioning 

       " i want do sort a column in a personalized order, not only asc or desc."

    So, then ascending and descending is not relevant??

     

    As for sorting by multiple columns, you need to utilize the SortByColumns function.  The Sort function will only sort on one column.  SortByColumns allows you to specify the column and the order and then repeat for additional columns.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    asc or desc is not relevant.

     

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Anonymous 

    One final question...the names of the colors are actually columns in your data??  You have a Green column, Red column, and Yellow Column??

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    i have one column with the values of colors. is a choice column in a sharepoint

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Anonymous 

    Ah, I see, you have a choice column that you want to sort specifically in this case.

     

    So, your button formula needs to be this:

    With({_default:
     Table({color:"Yellow"; order:1}; {color:"Red"; order:2}; {color: "Green"; order:3})
     },
    
    UpdateContext({lclSortColumns:
     Switch(LookUp(Coalesce(lclSortColumns; _default); order=1).color;
     "Green"; Table({color:"Yellow"; order:1}; {color:"Red"; order:2}; {color: "Green"; order:3});
     "Yellow"; Table({color:"Yellow"; order:3}; {color:"Red"; order:1}; {color: "Green"; order:2});
     "Red"; Table({color:"Yellow"; order:2}; {color:"Red"; order:3}; {color: "Green"; order:1})
     )
    })

     

    And your Items formula this:

    SortByColumns(
     AddColumns(
     <yourCurrentFormula - which needs to be refactored!>;
     "_order"; 
     LookUp(
     Coalesce(lclSortColumns;
     Table({color:"Yellow"; order:1}; {color:"Red"; order:2}, {color: "Green"; order:3})
     ); color=Overal.Value
     ).order
     );
     "_order"
    )
    
  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    so i tryed and doesnt work.. to make more easy let me show to you . this is my Item property

    Switch(
     varsorteia;
     "overal";
     If(
     fazfiltro = "1";
     Sort(
     Filter(
     colecaotudo;
     ID > 1;//not list configuration line
     LoSFlag = true;
     'Planned to' <= planned.SelectedDate + 1 Or FunctionLeadFilter.Selected.Result in 'Function Lead'.DisplayName Or Stage.Value in StageFilter.Selected.Result Or DBSLeadFilter.Selected.Result in 'DBS Lead'.DisplayName Or Function.Value in FunctionFilter.Selected.Result
     );
     Overal.Value;
     sortdirection
     );
     Sort(
     Filter(
     colecaotudo;
     ID > 1;//not list configuration line
     LoSFlag = true
     );
     Overal.Value;
     sortdirection
     )
     )
    )

     this  is the onselect

    Set(
     varsorteia;
     "overal"
    ) & Set(
     sortdirection;
     If(
     sortdirection = Ascending;
     Descending;
     Ascending
     )
    )

    and i have this issues.. 

    giampaulo_0-1642004844824.png

    doesnt recognize the 

    lclSortColumns
    and in the items i tryed but is the same..
  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Anonymous 

    Yes, that Items property needs to be redone.

     

    Sorry I missed a closing paren in the Button OnSelect formula.  Should be:

    With({_default:
     Table({color:"Yellow"; order:1}; {color:"Red"; order:2}; {color: "Green"; order:3})
     },
    
     UpdateContext({lclSortColumns:
     Switch(LookUp(Coalesce(lclSortColumns; _default); order=1).color;
     "Green"; Table({color:"Yellow"; order:1}; {color:"Red"; order:2}; {color: "Green"; order:3});
     "Yellow"; Table({color:"Yellow"; order:3}; {color:"Red"; order:1}; {color: "Green"; order:2});
     "Red"; Table({color:"Yellow"; order:2}; {color:"Red"; order:3}; {color: "Green"; order:1})
     )
     })
    )

     

    Items property:

    SortByColumns(
     AddColumns(
     Filter(colecaotudo;
     !IsBlank(ID);
     LoSFlag; 
     !(fazfiltro = "1") || 
     fazfiltro = "1" && ('Planned to' <= DateAdd(planned.SelectedDate, 1, Days) || FunctionLeadFilter.Selected.Result in 'Function Lead'.DisplayName || Stage.Value in StageFilter.Selected.Result || DBSLeadFilter.Selected.Result in 'DBS Lead'.DisplayName || Function.Value in FunctionFilter.Selected.Result)
     );
     "_order"; 
     LookUp(
     Coalesce(lclSortColumns;
     Table({color:"Yellow"; order:1}; {color:"Red"; order:2}, {color: "Green"; order:3})
     ); color=Overal.Value
     ).order
     );
     "_order", sortdirection
    )

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 416 Most Valuable Professional

#2
11manish Profile Picture

11manish 205 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 128 Super User 2026 Season 2

Last 30 days Overall leaderboard