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 Gallery with vari...
Power Apps
Unanswered

Sort Gallery with variable, problem with DateTimeValue

(0) ShareShare
ReportReport
Posted on by 64

Hi everybody, 

 

I built an app for writing down documentations. They show up in a gallery and I want to sort the items by using three buttons (see screenshot). 

Button1: Sort by client (KlientIn)

Button2: Sort by time (Leistungserbringung von)

Button3: Sort by employee (MitarbeiterIn)

I am using two variables: 

Variable1: var_SortColumn

Variable2: var_SortDirection

 

The Gallery Items property looks like Screenshot2 (App2). 

 

The OnSelect property of Button1 looks like Screenshot3 (App3).

 

Sort by KlientIn and sort by MitarbeiterIn ist working fine. Sort by "Leistungserbringung von" is not giving me an error, but neither sorting the items by time (just random sorting). 

 

Can somebody help with that?  Thanks in advance! 

App3.png
App2.png
App1.png
Categories:
  • shoog Profile Picture
    2,164 on at

    You seem to be missing some If functions in the else part of the first If function.

    Correct syntax would be like:

    If(var_SortColumn = "KlientIn", KlientIn.Value,
     If(var_SortColumn = "Leistungs...", DateTimeValue(...),
     If(var_SortColumn = "MitarbeiterIn", ...
     )
     )
    )

     

  • Frank89 Profile Picture
    64 on at

    Hi @shoog and thanks for your response! 

    If I use your syntax nothing is working anymore. With my syntax the sorting of Klient and Mitarbeiter is working fine (descending and ascending). Only the sorting by time is not working...

     If(
     var_SortColumn = "KlientIn",
     KlientIn.Value,
     var_SortColumn = "Leistungserbringung von",
     DateTimeValue(
     Text(
     'Leistungserbringung von',
     "dd.mm.yyyy" & " hh:mm"
     )
     ),
     var_SortColumn = "MitarbeiterIn",
     MitarbeiterIn.DisplayName
     ),
     var_SortDirection
    )

     

  • v-chenzhi Profile Picture
    Microsoft Employee on at

    Hi @Frank89 ,

     

    Could you please tell me what your data source is and what is the type of the 'Leistungserbringung vo' column?

    I assume that your data source is SharePoint and the column is text column.

    I have a test on my sdie, please try the following solutions.

    I created this in SharePoint.

    vchenzhi_0-1639536036309.png

    Set the items property of Gallery to following:

     

    Sort(
     ListName,
     If(
     var_SortColumn = "Leistungserbringung von",
     DateTimeValue(
     Text(
     'The Text',
     "dd/mm/yyyy" & "hh:mm"
     )
     )
     ),
     var_SortDirection
    )

    It works fine.

     

      vchenzhi_1-1639536372212.png             vchenzhi_2-1639536402851.png

     

     

    Best Regards,

    Zhi Chen

     

     

     

  • Frank89 Profile Picture
    64 on at

    Hi @v-chenzhi, 

     

    I can show you the whole Items property of the Gallery. 

    Source is a Collection collected from SPO and the "Leistungserbringung von" column is a Date and Time column. 

    As I said, everything works fine except the sorting of "Leistungserbringung von". 

    Here the whole syntax: 

    Sort(
     Filter(
     colDoku,
     If(
     !IsBlank(DBauswahl_dropdown_mitarbeiterin),
     DBauswahl_dropdown_mitarbeiterin.Selected.Result in MitarbeiterIn.DisplayName,
     true
     ),
     If(
     !IsBlank(DBauswahl_dropdown_entwicklungsbereich),
     DBauswahl_dropdown_entwicklungsbereich.Selected.Result in 'Entwicklungsbereich 1'.Value,
     true
     ),
     If(
     !IsBlank(DBauswahl_dropdown_klient),
     DBauswahl_dropdown_klient.Selected.Result in KlientIn.Value,
     true
     ),
     If(
     !IsBlank(DBauswahl_datepicker_von),
     DBauswahl_datepicker_von.SelectedDate <= 'Leistungserbringung von',
     true
     ),
     If(
     !IsBlank(DBauswahl_datepicker_bis),
     DateAdd(
     DBauswahl_datepicker_bis.SelectedDate,
     1,
     Days
     ) > 'Leistungserbringung bis',
     true
     ),
     If(
     DBauswahl_dropdown_absagen.Selected.Value = "Ausfälle ausschließen",
     !'kurzfristig abgesagt',
     true
     ),
     If(
     DBauswahl_dropdown_absagen.Selected.Value = "nur Ausfälle anzeigen",
     'kurzfristig abgesagt',
     true
     )
     ),
     If(
     var_SortColumn = "KlientIn",
     KlientIn.Value,
     var_SortColumn = "Leistungserbringung von",
     DateTimeValue(
     Text(
     'Leistungserbringung von',
     "dd/mm/yyyy" & "hh:mm"
     )
     ),
     var_SortColumn = "MitarbeiterIn",
     MitarbeiterIn.DisplayName
     ),
     var_SortDirection
    )

     

     

  • WarrenBelz Profile Picture
    156,754 Most Valuable Professional on at

    Hi @Frank89 ,

    If 'Leistungserbringung von' is a date to start with, why change it to text and back again?

    Sort(
     Filter(
     colDoku,
     (
     !IsBlank(DBauswahl_dropdown_mitarbeiterin) ||
     DBauswahl_dropdown_mitarbeiterin.Selected.Result in MitarbeiterIn.DisplayName
     ) &&
     (
     !IsBlank(DBauswahl_dropdown_entwicklungsbereich) ||
     DBauswahl_dropdown_entwicklungsbereich.Selected.Result in 'Entwicklungsbereich 1'.Value
     ) &&
     (
     !IsBlank(DBauswahl_dropdown_klient) ||
     DBauswahl_dropdown_klient.Selected.Result in KlientIn.Value
     ) &&
     (
     !IsBlank(DBauswahl_datepicker_von) ||
     DBauswahl_datepicker_von.SelectedDate <= 'Leistungserbringung von'
     ) &&
     (
     !IsBlank(DBauswahl_datepicker_bis) ||
     DateAdd(
     DBauswahl_datepicker_bis.SelectedDate,
     1,
     Days
     ) > 'Leistungserbringung bis'
     ) &&
     (
     DBauswahl_dropdown_absagen.Selected.Value <> "Ausfälle ausschließen" ||
     !'kurzfristig abgesagt'
     ) &&
     ( 
     DBauswahl_dropdown_absagen.Selected.Value = "nur Ausfälle anzeigen" ||
     'kurzfristig abgesagt'
     ) 
     ),
     Switch(
     var_SortColumn,
     "KlientIn",
     KlientIn.Value,
     "Leistungserbringung von",
     'Leistungserbringung von',
     "MitarbeiterIn",
     MitarbeiterIn.DisplayName
     ),
     var_SortDirection
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

  • Frank89 Profile Picture
    64 on at

    Hi @WarrenBelz 

    it is not working yet. If I sort all entries from november, it goes like

    09.11.21

    08.11.21

    07.11.21

    04.11.21

    30.11.21

    03.11.21

    29.11.21

    28.11.21

    ...

    20.11.21

    02.11.21

    19.11.21

    18.11.21

     

    Any idea, how I can change the sorting, that the date format is not causing this problem? 

    Thanks, Simon

  • Frank89 Profile Picture
    64 on at

    Hi @WarrenBelz 

    The upper part of your syntax is not working. So I kept my part with the If-statements and changed only this syntax part: 

       Switch(

          var_SortColumn,

          "KlientIn",

          KlientIn.Value,

          "Leistungserbringung von",

          'Leistungserbringung von',

          "MitarbeiterIn",

          MitarbeiterIn.DisplayName

        ),

        var_SortDirection

    )

  • WarrenBelz Profile Picture
    156,754 Most Valuable Professional on at

    Hi @Frank89 ,

    Is the field a date?

  • Frank89 Profile Picture
    64 on at

    Hi @WarrenBelz 

    Yes, it's a date field.

  • WarrenBelz Profile Picture
    156,754 Most Valuable Professional on at

    @Frank89 ,

    Then there is no reason that 

    Switch(
     var_SortColumn,
     "KlientIn",
     KlientIn.Value,
     "Leistungserbringung von",
     'Leistungserbringung von',
     "MitarbeiterIn",
     MitarbeiterIn.DisplayName
     ),

    would not sort on the date field 'Leistungserbringung von' if varSortField was set to "Leistungserbringung von". Is this what you are saying?

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 342 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 271

#3
Mohsin Ali Profile Picture

Mohsin Ali 239

Last 30 days Overall leaderboard