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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Changing my Sort so ti...
Power Apps
Unanswered

Changing my Sort so title=NOTES is on top

(1) ShareShare
ReportReport
Posted on by 674
Hey there,
 
So for one of my galleries, I currently have this as the sort : 
 
Sort(Filter(Saginaw, 'Start Date' <= DateTimeValue(FakeDate_1.Text) And 'End Date' >= DateTimeValue(FakeDate_1.Text)),'Start Time',SortOrder.Ascending)
 
It mostly just sorts by the start time, but I have a 'fake date' in case they choose no time.  I want to make it so that if 'Title'=NOTES, they it goes on top, but I'm not sure how to inject that here, and my attempts have been horrible. Any help would be appreciated.
Categories:
I have the same question (0)
  • Michael E. Gernaey Profile Picture
    53,325 Super User 2025 Season 2 on at
     
    I wanted to first say, I am guessing you are getting delegation warnings since you are using DateTimeValue. If that is the case I just wanted to give some advice for that first.
     
    Change it too
     
    With(
         { _DateValue: DateTimeValue(FakeDate_1.Text) },
    
        Sort(Filter(Saginaw, 'Start Date' <= _DateValue And 'End Date' >= _DateValue,'Start Time',SortOrder.Ascending)
    );
     
    Ok now let's talk about your second question (ok wait lol you didn't ask the first question, I just thought I would suggest it)
     
    In this one, I want to make sure I completely understand.
     
    You said if Title = "Notes" then you want them on top, so let's pretend that you have 1000 records.
    Let;s further pretend that 100 of the 1000 have Title = "Notes"
     
    So when I sort, you want those 100 first, and then the 900?
     
    And if so:
    1) what is the sort order of the 100? I know you wanted them on top, but what is their sort order
    2) what is the sort order of the 900 that are left?
     
     
    P.S. I could not help but think Michigan, when I saw Saginaw
  • MarkRahn Profile Picture
    1,229 Super User 2025 Season 2 on at
     
    Looking at the statement you provided, I noticed that you have 'Start Date' and 'Start Time' as two separate fields. For the example I did I just have 'Start Date' which contains Date and Time.
     
    Working off of the example that @Michael E. Gernaey provided using the "With" function, you could go with the following:
    With(
        {_DateValue0000: DateValue(FakeDate_1.Text),
         _DateValue2359: DateValue(DateAdd(DateValue(FakeDate_1.Text),1,TimeUnit.Days))
        },
        SortByColumns(
            AddColumns(
                Sort(
                    Filter(
                        Saginaw,
                        'Start Date' <= _DateValue2359 And 'End Date' >= _DateValue0000
                    ),
                    'Start Date',
                    SortOrder.Ascending
                ),
                TitleSort,
                If(
                    ThisRecord.Title = "NOTES",
                    0,
                    1
                )
            ),
            "TitleSort",
            SortOrder.Ascending
        )
    )
     
    This is what the mock up looks like:
    The items are sorted by Title = "NOTES" or not "NOTES", and then "Start Date". To filter on the "FakeDate_1" field assuming that it was just a date value, the code generates DateTime values between 12AM on the date entered and 12AM on the next day. You should adjust to fit your needs.
     
    Hopefully the example of using "Add Columns" and "SortByColumns" can get you closer to your own solution. You could remove the internal "Sort" and go with more than one field in the "SortByColumns" just keep in mind to double check the field names that come back from your "Filter" as they will be the Internal Names.
     
    Depending on your data source you may still have issues with Delegation so keep that in mind.
     
    This community is supported by individuals freely devoting their time to answer questions and provide support. They do it to let you know you are not alone. This is a community.

    If someone has been able to answer your questions or solve your problem, please click Does this answer your question. This will help others who have the same question find a solution quickly via the forum search.

    If someone was able to provide you with more information that moved you closer to a solution, throw them a Like. It might make their day. 😊

    Thanks
    -Mark
  • CharlesBrewer Profile Picture
    674 on at
     
    Hey so that kind of works. It does seem to sort and put the NOTES on top. Here is what it looks like, it's basically a weird 1 week calendar.
     
    The problem is they used to be able to click on one of these entries and edit, but now they can't  after this Sort change : 
     
    There seems to be an error now for the Edit form item : 
  • CharlesBrewer Profile Picture
    674 on at
    Actually no, it was also duplicating and making 1 day items into 2 day items, so that broke it. :(
  • Michael E. Gernaey Profile Picture
    53,325 Super User 2025 Season 2 on at
     
    If you wouldn't mind answering my original questions, I am happy to step away, but what exactly do you want and in what order.
  • CharlesBrewer Profile Picture
    674 on at
     
    I think I'm still awaiting a response from you on my other post about the commas for Automate (https://community.powerplatform.com/forums/thread/details/?threadid=2607ee89-94fb-ef11-be20-7c1e5266971b) :) But anyways...
     
    If I understand you correctly, basically for each day (you can see the picture below), I would want Notes on Top, then sorted by time for each date, then the No Time (that's the fakedate). That should work, I think. It is a gallery within a gallery so there is the calendar gallery and then each day is a gallery also.
  • MarkRahn Profile Picture
    1,229 Super User 2025 Season 2 on at
     
    WOW! That is a lot of color.
     
    Are you able to post what you have in the Gallery for the Items?
     
    And can you post an example of what your data looks like with the fields used in the Items - Filter? Such as 'Start Date', 'End Date', 'Title', and 'Start Time".
     
    Is this a Gallery in a Gallery? Or do you have a Gallery for each day?
     
    Is varPopUpRecord set for the OnSelect? The prior Filter had the return Items match Saginaw. When the code was modified to add TitleSort, it may have changed the Item so it does not match anymore. If you have an ID field, you could do a LOOKUP call using the ID to set varPopUpRecord.
     
    Anything you can provide will give me the chance to work on it more.
     
    This community is supported by individuals freely devoting their time to answer questions and provide support. They do it to let you know you are not alone. This is a community.

    If someone has been able to answer your questions or solve your problem, please click Does this answer your question. This will help others who have the same question find a solution quickly via the forum search.

    If someone was able to provide you with more information that moved you closer to a solution, throw them a Like. It might make their day. 😊

    Thanks
    -Mark
  • CharlesBrewer Profile Picture
    674 on at
    Haha yes, the reason for the color is they wanted each user to be able to set their own background color/text. Which was fun to figure out, on my end. I should mention I don't do PowerApps very often and I made this like a year ago, so it's hard to remember how any of this works but I'll give it my best.
     
    Are you able to post what you have in the Gallery for the Items?
    -That is what's in my Gallery for Items : 
    Sort(Filter(Saginaw, 'Start Date' <= DateTimeValue(FakeDate_1.Text) And 'End Date' >= DateTimeValue(FakeDate_1.Text)),'Start Time',SortOrder.Ascending)
    And can you post an example of what your data looks like with the fields used in the Items - Filter? Such as 'Start Date', 'End Date', 'Title', and 'Start Time".
    The 1900 date gets put in if they don't have a time. There is actually a 'No Time' checkbox.
     
    Is this a Gallery in a Gallery? Or do you have a Gallery for each day?
    -It is a gallery in a gallery. The calendar is a gallery and then the day is a gallery that has 7 columns, basically? I think I explained that right.
     
    Is varPopUpRecord set for the OnSelect? The prior Filter had the return Items match Saginaw. When the code was modified to add TitleSort, it may have changed the Item so it does not match anymore. If you have an ID field, you could do a LOOKUP call using the ID to set varPopUpRecord.
    It's the Item?
     
     
    Sorry I'm not very good at explaining my own work, I kind of tumbled through it a long time ago
  • MarkRahn Profile Picture
    1,229 Super User 2025 Season 2 on at
     
    I am going to make an assumption that you are using a SharePoint List to store this data. (If not, then we need to come up with something else)
     
    Go into the list and add a Calculated Column like the following:
     
    Then your Gallery Items property can be set to:
    Sort(Sort(Filter([@Saginaw], 'Start Date' <= DateTimeValue(FakeDate_1.Text) && 'End Date' >= DateTimeValue(FakeDate_1.Text)),'Start Time',SortOrder.Ascending),'NotesSort',SortOrder.Ascending)
     
    You will have a Delegation warning but that just means that whatever you get back from the first Sort will need to be handled client side.
     
    Let me know if that works for you. You could have gotten the last code I provided working if you had put something like this in your Gallery OnSelect function:
    Set(varPopUpRecord,LookUp(Saginaw,ID=ThisItem.ID));
     
    You were probably just setting varPopUpRecord to ThisItem which does not work now because the code I gave you added another column.
     
    Let me know if any of these suggestions work for you.
     
    This community is supported by individuals freely devoting their time to answer questions and provide support. They do it to let you know you are not alone. This is a community.

    If someone has been able to answer your questions or solve your problem, please click Does this answer your question. This will help others who have the same question find a solution quickly via the forum search.

    If someone was able to provide you with more information that moved you closer to a solution, throw them a Like. It might make their day. 😊

    Thanks
    -Mark

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard