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 Platform Community / Forums / Power Apps / Sort is breaking Alter...
Power Apps
Answered

Sort is breaking Alternate Row Color

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I may have gone about this wrong, but this is where I am at.

 

So we have two sets of engineers.

We can filter our list based on those engineers, and then we are also filtering that list with their current status.

We then SORT by their queue status.

So for example, if I pick Tech Talk, the code in on the filter button is this:

If(
 l_TechTalk,
 ClearCollect(
 col_Engineers,
 Filter(
 col_Engineers,
 EngineerQueueStatus.Value = "TechTalkLiveMeeting" || EngineerQueueStatus.Value = "TechTalkLiveSoon"
 )
 )
);

Another example, if we choose "in Office", this is the code to filter and sort those engineers

If(l_inoffice=true,
 ClearCollect(
 col_Engineers,SortByColumns(
 AddColumns(
 EngineersV2,"EngineerQueueStatus_value",EngineerQueueStatus.Value),
 "EngineerQueueStatus_value",["Available","Out of Queue Soon","In Queue Soon","In Queue Later",
 "Out of Queue","Assign No Cases","Assign No Crits","Assign Only Crits","TechTalkLiveMeeting","TechTalkLiveSoon"]
 )
 ),
 ClearCollect(col_Engineers,SortByColumns(EngineersV2,"Total_x0020_Assigned",SortOrder.Descending
 )
 )
);

At the end of the code block on Filter, we are setting row numbers

Clear(col_Display);
ForAll(col_Engineers, 
 Collect(col_Display,
 Last(FirstN(AddColumns(col_Engineers,
 "RowNumber",
 CountRows(col_Display)+1
 ), 
 CountRows(col_Display)+1
 )
 ) 
 )
);

On the gallery item, under FILL, we are setting the colors for the alternating row.

If(Mod(Value(ThisItem.RowNumber),2)=0,Color!WhiteSmoke,
If(Mod(Value(ThisItem.RowNumber),1)=0,Color!White))))

The problem I am having is keeping the alternate row colors AFTER I do an additional SORT

Here is an example of getting a specific set of engineers, who are all in office.

It sorts by queue status, and I have my alternating rows.

lardo5150_0-1692306027883.png

Now, lets say I take my current gallery items from the filter and I want to sort that by Accept Time:

lardo5150_1-1692306136558.png

You can see that my alternating row colors gets messed up.

 

So the previous owner built it so the variable col_display gets its row numbers in the filter button.

 

Now using Accept Time Sort, on select of that icon, I have the following code:

UpdateContext({acceptTimeSortDescending: !acceptTimeSortDescending});
UpdateContext({AcceptTimeVisible: !AcceptTimeVisible});
UpdateContext({EXOCountSortDescending: false});
UpdateContext({EXOCountVisible: false});
UpdateContext({CritCountSortDescending: false});
UpdateContext({CaseCountSortDescending: false});
UpdateContext({CaseCountVisible: false});
UpdateContext({CritCountVisible: false});

So when I hit the sort button for Accept time, it makes it true, hitting it again, false.

I set the other sorts to false as well.

Here is what I have my gallery items set to

//col_Display
If(acceptTimeSortDescending = true,
SortByColumns(col_Display,"Last_x0020_Assigned",SortOrder.Descending),
If(EXOCountSortDescending = true,
SortByColumns(col_Display,"EXOCaseCount",SortOrder.Descending),
If(CritCountSortDescending = true,
SortByColumns(col_Display,"Crits_x0020_Assigned",SortOrder.Descending),
If(CaseCountSortDescending = true,
SortByColumns(col_Display,"Total_x0020_Assigned",SortOrder.Descending),col_Display))))

When I hit sort i would like to keep the same format, alternating row colors.

But it seems since the gallery is already set with row numbers, when sorting, it messes up the alertanting rows.

Does anyone have any ideas on how to keep the alternating row colors?

 

Categories:
  • lardo5150 Profile Picture
    Microsoft Employee on at

    @RandyHayes  I tried your solution via the video you posted:

    https://www.youtube.com/watch?v=v66-rwPkVvA

     

    I could never get it to work.  I really think I am doing something in other steps, that is preventing it from working correclty, but not sure where.

  • Verified answer
    EddieE Profile Picture
    4,650 Moderator on at

    @lardo5150 

    You could try using the method presented by @WarrenBelz in this article

     

    https://www.practicalpowerapps.com/useful-tips/#Alternate

     

    You would remove your code that applies row numbers and use his method. You would also need to remove the Fill property code and use TemplateFill instead

     

  • lardo5150 Profile Picture
    Microsoft Employee on at

    Eddie, I am trying this, but it is throwing an error of it needs to be true or false.

    i will admit, I have never worked with the WITH function.

    I thought that you just wrap your code with the WITH function, but that is not working for me.

    My original code:

    //col_Display
    If(acceptTimeSortDescending = true,
    SortByColumns(col_Display,"Last_x0020_Assigned",SortOrder.Descending),
    If(EXOCountSortDescending = true,
    SortByColumns(col_Display,"EXOCaseCount",SortOrder.Descending),
    If(CritCountSortDescending = true,
    SortByColumns(col_Display,"Crits_x0020_Assigned",SortOrder.Descending),
    If(CaseCountSortDescending = true,
    SortByColumns(col_Display,"Total_x0020_Assigned",SortOrder.Descending),col_Display))))

    Since we are not using col_display anymore, I am just using col_Engineers

    lardo5150_0-1692358643821.png

     

    ith(
     {
     wList:
     Filter(col_Engineers,
    If(acceptTimeSortDescending = true,
    SortByColumns(col_Engineers,"Last_x0020_Assigned",SortOrder.Descending))
     },
     ForAll(
     Sequence(CountRows(wList)),
     Patch(
     Index(
     wList,
     Value
     ),
     {RowNo: Value}
     )
     )
    )

    To make things easy, I just added one of the IF statements, not all of them, to see if I could get it working.

  • lardo5150 Profile Picture
    Microsoft Employee on at

    Ok, I started simple, I got the alternate rows working, but I do not know how to set the sorting.

    My items:

    //col_Display
    With(
     {
     wList:col_Engineers
    
     
     },
     ForAll(
     Sequence(CountRows(wList)),
     Patch(
     Index(
     wList,
     Value
     ),
     {RowNo: Value}
     )
     )
    ) 

    Gallery TemplateFill

    If(Mod(Value(ThisItem.RowNo),2)=0,Color!WhiteSmoke,
    If(Mod(Value(ThisItem.RowNo),1)=0,Color!White))

    The problem I have now is getting my Sorts to work again.

  • lardo5150 Profile Picture
    Microsoft Employee on at

    Ok, I got the sorting formulas in also and that works, but then I lose the alternating rows because I can't seem to figure out how to combine these if statements with the ForAll for the rows, inside the WITH()

     

    With(
     {
     wList:col_Dipslay
    
     
     },
    
     //ForAll(Sequence(CountRows(wList)),Patch(Index(wList,Value),{RowNo: Value}))
     If(acceptTimeSortDescending = true,
    SortByColumns(wList,"Last_x0020_Assigned",SortOrder.Descending),
    If(EXOCountSortDescending = true,
    SortByColumns(wList,"EXOCaseCount",SortOrder.Descending),
    If(CritCountSortDescending = true,
    SortByColumns(wList,"Crits_x0020_Assigned",SortOrder.Descending),
    If(CaseCountSortDescending = true,
    SortByColumns(wList,"Total_x0020_Assigned",SortOrder.Descending),wList)
    ))))
  • Verified answer
    lardo5150 Profile Picture
    Microsoft Employee on at

    I think I got it!!!

    @EddieE  I used that article you sent (plus a few other examples) and was able to combine both the for all with the sorts.

    Maybe there is a better way, but so far in my testing this is working.

     

    With(
     {
     wList:If(acceptTimeSortDescending = true,SortByColumns(col_Display,"Last_x0020_Assigned",SortOrder.Descending),
     If(EXOCountSortDescending = true,SortByColumns(col_Display,"EXOCaseCount",SortOrder.Descending),
     If(CritCountSortDescending = true,SortByColumns(col_Display,"Crits_x0020_Assigned",SortOrder.Descending),
     If(CaseCountSortDescending = true,SortByColumns(col_Display,"Total_x0020_Assigned",SortOrder.Descending),col_Display))))
    
     
     },
     ForAll(
     Sequence(CountRows(wList)),
     Patch(
     Index(
     wList,
     Value
     ),
     {RowNo: Value}
     )
     )
    ) 
  • EddieE Profile Picture
    4,650 Moderator on at

    @lardo5150 

    Well done!


    If your issue is resolved please mark it as solved. You can choose more than one solution if you think that will help other users.

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 345 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 312

#3
Mohsin Ali Profile Picture

Mohsin Ali 252

Last 30 days Overall leaderboard