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

Custom sort order for phone list (several locations)

I am creating a phone book for different locations in my company.
When opening the app, people can choose Location 1, Location 2, …

If they choose Location 2, they will enter a Gallery which show the different departments/categories for the location.


At the moment these are in a table called «Departments» with the following columns:

- Location

- Department


Because I want the first entry of the gallery to be «all numbers» (for every location), I choose to make a collection where I manually create the first entry and then collect the rest of the departments depending on chosen location.


I need help with:

Per location there is one data administrator.

How can I create a simple way for the administrator to choose which department will show on top (below All numbers)?


I know the following code will give the desired order:

SortByColumns( DataSource, Column, [ " Not Started","In Progress","Approved","Rejected","On Hold " ] ) 

But when different locations have different departments, this will not work.

What is the best solution? Create an extra column in the Departments table called sort number?

Dropdown menu with a choice of numbers for each department?
How can I make sure that 15 different numbers are chosen if a location have 15 different departments?
If two new departments are added and wanted as number 2 / 3, how can we make this happen without having to manually change the numbers of each department?


I hope there is a simple solution for this which I do not know about, yet! 🙂

Resident Rockstar
Resident Rockstar

Hi @mrstian89 


Please check this post 

Thank you
If this post helps, then please consider Accept it as the solution to help the others and consider giving it a "Thumbs Up."
Helper III
Helper III

Thanks for the repsond, but this does not solve my problem of wanting each location to be able to customize the order of the categories/departments.

Helper III
Helper III

Still not found the solution, but I feel like I am getting closer.

I have made a ComboBox which includes my categories.


I select my custom order in the combobox, and create a string based on this with the following code:

    {wString: Char(34) & "All" & Char(34) & "," & Char(34) & Concat(ComboBox1.SelectedItems,Avdeling & Char(34),"," & Char(34))},
    If(Right(wString,1)=",",Left(wString, Len(wString)-1),wString);
    Patch('Phone - Category' , LookUp('Phone - Category', Plant = myPlant),
{ Sortering: wString });Set(Test,wString));

This gives me the following string:



If I use this string directly to sort my Gallery, it works just as I hoped:

SortByColumns(collectDepartments,"Result", ["All","Category1","Category10","Category5"]) 


But I cannot use it directly, so I have to use it as a variable (get it from a table column).


SortByColumns(collectDepartments,"Result", [SortStringVariable]) 

When I make the sort order into a variable, it does not sort as expected.
I believe this is because you cannot sort by a string?


Is there any way that I can use this sort string to sort a gallery?
I store in in a column in a Dataverse table. 

Helpful resources

2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

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