cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AshishJaiswal
Super User
Super User

Sorting not working

Hi Experts,
Sorting is only working in one direction - if ascending then it stays in it doesn't descend when click on icon.

 

I am using the below formula to sort items in my gallery.

 

Sort Icon (on select) = 

Set(
    varSortColumn,
    "Title"
);
Set(
    varSortDirection,
    If(
        varSortDirection = Ascending,
        Ascending,
        Descending
    )
)

 
Then I have my gallery 

Switch(
    varSortColumn,
    "Title",
    SortByColumns(
        Filter(
            'DWP Technology & Service Register',
            'Product / Service (Title)' = ComboBox1.Selected.'Product / Service (Title)' || IsBlank(ComboBox1.Selected.'Product / Service (Title)')
        ),
        "Title",
        If(
            varSortColumn = Ascending,
            Ascending,
            Descending        )
    ),
    "Technology_x0020_Grouping",
    SortByColumns(
        Filter(
            'DWP Technology & Service Register',
            'Product / Service (Title)' = ComboBox1.Selected.'Product / Service (Title)' || IsBlank(ComboBox1.Selected.'Product / Service (Title)')
        ),
        "Technology_x0020_Grouping",
        If(
            varSortColumn = Ascending,
            Ascending,
            Descending
        )
    )
)



 

4 REPLIES 4
timl
Super User
Super User

@AshishJaiswal 

Assuming that you want your sort icon to toggle the sort order, this logic should hopefully work better for you.

 

Set(
    varSortColumn,
    "Title"
);
Set(
    varSortDirection,
    Switch( varSortDirection, 
            Descending, Ascending, 
            Ascending, Descending, 
            Ascending
    )
)

 

@timl 

Issue is in gallery.

 

Gallery items aren't sorting as per the sort icon 

timl
Super User
Super User

Hi @AshishJaiswal 

In addition to the above, if you modify the Items property of the gallery to reference varSortDirection only, that should hopefully work.

 

Switch(
    varSortColumn,
    "Title",
    SortByColumns(
        Filter(
            'DWP Technology & Service Register',
            'Product / Service (Title)' = ComboBox1.Selected.'Product / Service (Title)' || IsBlank(ComboBox1.Selected.'Product / Service (Title)')
        ),
        "Title",
        varSortDirection
    ),
    "Technology_x0020_Grouping",
    SortByColumns(
        Filter(
            'DWP Technology & Service Register',
            'Product / Service (Title)' = ComboBox1.Selected.'Product / Service (Title)' || IsBlank(ComboBox1.Selected.'Product / Service (Title)')
        ),
        "Technology_x0020_Grouping",
        varSortDirection
    )
)

 

@timl 

Correct but using the variable varsortdirection gives me delegation warning to aviod that i was using 

If(
            varSortColumn = Ascending,
            Ascending,
            Descending        )

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 (4,646)