cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dgarcia
Frequent Visitor

Help with merging two Sort options

I am trying to merge two separate working search/ Sort options. the following is the code i currently have that works separately. 

 

 

 

Sort(If(type="All",Tickets,If(type="Tickets older than 2 days", Filter(Tickets,   DateCreated <> datetype && DateCreated <>Text(Today()), DateCreated <> Text(DateAdd(Today(), -2)),DateCreated <> Text(DateAdd(Today(),  -1))|| DateClosed <> datetype && DateClosed <> Text(Today()), DateClosed <> Text(DateAdd(Today(), -2)),DateClosed <> Text(DateAdd(Today(), -1))), If(type="Tickets opened today",Filter(Tickets,datetype in DateCreated), If(type="Tickets closed today",Filter(Tickets,datetype in DateClosed),Filter(Tickets,type in Status))
))),ID,Descending)
SortByColumns(Filter('Tickets',StartsWith('CreatedBy',Search_po.Text) || StartsWith(AssignedTo,Search_po.Text) || StartsWith(Service_Num,Search_po.Text)|| StartsWith(Status,Search_po.Text)), "ID", If(SortDescending1,SortOrder.Ascending, SortOrder.Descending))

 

 

Any help is appreciated. 

2 REPLIES 2
Drrickryp
Super User
Super User

@dgarcia 

To simplify, using Switch instead of multiple If() statements in the first formula and putting that entire formula in a With() statement and aliasing that table as tkts, apply the second formula and sort the final result.  You should check the ")" to make sure I haven't missed any.  

 

With({tkts: Switch(type,"All",Tickets,
                        "Tickets older than 2 days", Filter(Tickets, And(
                                                                     DateCreated <> datetype,
                                                                     DateCreated <>Text(Today()), 
                                                                     DateCreated <> Text(DateAdd(Today(),-2)),
                                                                     DateCreated <> Text(DateAdd(Today(),-1))) || 
                                                                     And(
                                                                         DateClosed <> datetype,
                                                                         DateClosed <> Text(Today()), 
                                                                         DateClosed <> Text(DateAdd(Today(),-2)),
                                                                         DateClosed <> Text(DateAdd(Today(), -1)))
								     )
                                                     ),
                        "Tickets opened today", Filter(Tickets,datetype in DateCreated), 
                        "Tickets closed today",Filter(Tickets,datetype in DateClosed),
                         Filter(Tickets,type in Status)
             )
       },

   SortByColumns(
              Filter(
                     tkts,Or(
                             StartsWith('CreatedBy',Search_po.Text),
                             StartsWith(AssignedTo,Search_po.Text), 
                             StartsWith(Service_Num,Search_po.Text), 
                             StartsWith(Status,Search_po.Text)
                          )
               ), "ID", If(SortDescending1,SortOrder.Ascending, SortOrder.Descending)
    )
)

 

No sir, this did not work. I get the following error now, "Invalid number of arguments: received 5, expected 2."2022-04-14_7-23-41.jpg

 And my gallery looks like this, and gives this error for each item: "Incompatible types for comparison. These types can't be compared: Error, Text." 
I'm still new to powerapps so I apologize for not being able to correct these issues. 

2022-04-14_7-24-56b.jpg

Helpful resources

Announcements
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Users online (1,789)