cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Search bar to search multi column

Hi All

 

I want to edit the search bar to search multi-column records but fail, it's wrong coding as below? Thanks for help.

 

SortByColumns(Filter([SiteLog], StartsWith(TicketNumber, TextSearchBox1.Text)), "Title", "Name", If(SortDescending1, Descending, Ascending))

1 ACCEPTED SOLUTION

Accepted Solutions

@hankycheng0621 

 

Try something like this instead:

 

SortByColumns(
    Filter(SiteLog,StartsWith(TicketNumber, TextSearchBox1.Text) || StartsWith(Name, TextSearchBox1.Text))
    ,"Title"    
    ,If(SortDescending1, SortOrder.Ascending, SortOrder.Descending)
    ,"Name"
    ,If(SortDescending1, SortOrder.Ascending, SortOrder.Descending)
    
)

 

 

Check new version of sample app app22b.msapp attached to this post as well in case it helps, with the new formula above in the app.

 

For more info on the Filter function, check on this guide:

Filter - docs.microsoft.com

 

Check if it helps @hankycheng0621 

View solution in original post

9 REPLIES 9
poweractivate
Most Valuable Professional
Most Valuable Professional

@hankycheng0621 

 

You must use this formula instead:

 

 

 

SortByColumns(Filter(SiteLog, StartsWith(TicketNumber, TextSearchBox1.Text)), "Title", If(SortDescending1, SortOrder.Descending, SortOrder.Ascending), "Name")

 

 

The following would also be valid:

 

 

SortByColumns(Filter(SiteLog, StartsWith(TicketNumber, TextSearchBox1.Text)), "Title", If(SortDescending1, SortOrder.Descending, SortOrder.Ascending), "Name", If(SortDescending1, SortOrder.Descending, SortOrder.Ascending))

 

 

However, the formula you gave results in an error.

 

According to 

 

Sort Syntax - Power Apps - docs.microsoft.com

 

SortByColumns( Table, ColumnName1 [, SortOrder1, ColumnName2, SortOrder2, ... ] )

 

Table - Required. Table to sort.

ColumnName(s) - Required. The column names to sort on, as strings.

SortOrder(s) - Optional. SortOrder.Ascending or SortOrder.Descending. SortOrder.Ascending is the default. If multiple ColumnNames are supplied, all but the last column must include a SortOrder.


 

The key is that

"If multiple ColumnNames are supplied, all but the last column must include a SortOrder."

In your case, you did the opposite. You gave the last column a SortOrder, but nothing else.

 

The formula bar in my case gave an error when using your formula of:

SortByColumns(Filter(SiteLog, StartsWith(TicketNumber, TextSearchBox1.Text)), "Title", "Name", If(SortDescending1, SortOrder.Descending, SortOrder.Ascending))

The above formula, which is similar to the one you gave in your post, gave me this error:

 

poweractivate_2-1658554439580.png

 

The specified column 'ascending' does not exist or is an invalid sort column type

 

I am not sure if this is the error you got.

 

However, try using this formula instead:

 

SortByColumns(Filter(SiteLog, StartsWith(TicketNumber, TextSearchBox1.Text)), "Title", If(SortDescending1, SortOrder.Descending, SortOrder.Ascending), "Name")

 

The following would also be valid:

 

SortByColumns(Filter(SiteLog, StartsWith(TicketNumber, TextSearchBox1.Text)), "Title", If(SortDescending1, SortOrder.Descending, SortOrder.Ascending), "Name", If(SortDescending1, SortOrder.Descending, SortOrder.Ascending))

 

 

Working sample msapp 

 

poweractivate_1-1658554258476.png

 

 

have attached a working sample msapp file app22.msapp if you would like to import a full, working example yourself for your convenience. The example contains a Collection to simulate a data source.

 

To use the sample msapp attached, follow these steps:

 

1) Download the msapp file attached to this post to Desktop or a folder of your choice, by clicking on it from this post (the attachment is at the very bottom of this post.)

2) Create a new, blank Power App Canvas App

3) Go to File -> Open -> Browse

poweractivate_0-1658554199144.png

 

 

4) Navigate to location of .msapp file from Step 1, select it, and press the "Open" button.

5) The working example msapp file should load

6) You can try the app and check the working formula and setup as well in the app and see if it gives you an idea what might be wrong in your app.

7) Click on Screen2 and back to Screen1 initially once or twice for best results, this is so OnVisible can be triggered so the simulated Collection can be initialized and so you can see the Gallery contents right away.

 

 

Check if it helps @hankycheng0621 

 

poweractivate
Most Valuable Professional
Most Valuable Professional

@hankycheng0621 

 

Let me explain you in more detail why your formula doesn't work in case it helps.

 

First,

 

According to 

 

Sort Syntax - Power Apps - docs.microsoft.com

 

SortByColumns( Table, ColumnName1 [, SortOrder1, ColumnName2, SortOrder2, ... ] )

 

Table - Required. Table to sort.

ColumnName(s) - Required. The column names to sort on, as strings.

SortOrder(s) - Optional. SortOrder.Ascending or SortOrder.Descending. SortOrder.Ascending is the default. If multiple ColumnNames are supplied, all but the last column must include a SortOrder.

So why does "all but the last column" have to include a SortOrder anyway?

 

poweractivate_0-1658554875841.png

 

Because SortByColumns looks for

SortByColumns(source, column, order, [ column2, order2, column3, order3])

 

If you provide SortByColumns(source, column, column, order)

(which is what you did)

 

SortByColumns(
    Filter(SiteLog,StartsWith(TicketNumber, TextSearchBox1.Text))
    ,"Title"    
    ,"Name"
    ,If(SortDescending1, SortOrder.Descending, SortOrder.Ascending)
)

 

poweractivate_2-1658555551633.png

it will fail

because It will interpret "Name" as an "order'

Since "Name" is not an "order" that's why you get the error.

 

Whereas, 

If you provide SortByColumns(source, column, order, column)

The last column not being followed by an order, that would be fine - that's why "all but the last column" requires an order if multiple columns are provided.

 

Makes sense?

 

The only thing that you might be wondering, is:

what's with that seemingly bizarre error?

 

The specified column 'ascending' does not exist or is an invalid sort column type

 

Actually, the error...makes sense!

 

A similar error might also show up instead of:

 

The specified column 'descending' does not exist or is an invalid sort column type

 

Here's why:

 

If you provide SortByColumns(source, column, column, order)

(which is what you did)

 

SortByColumns(
    Filter(SiteLog,StartsWith(TicketNumber, TextSearchBox1.Text))
    ,"Title"    
    ,"Name"
    ,If(SortDescending1, SortOrder.Descending, SortOrder.Ascending)
)

 

It's expecting you to provide SortByColumns(source, column, order, column)

but if you instead provide    SortByColumns(source, column, column, order)

 

Notice carefully how not only is the 3rd argument given a column when it should be an order,

but more importantly, the 4th argument given is an 'order' when it should be a 'column'

 

So that means:

 

(now I'll use an example that will give the 'descending' version of the error rather than 'ascending', by just slight changing the 4th argument a little bit)

 

SortByColumns(
Filter(SiteLog,StartsWith(TicketNumber, TextSearchBox1.Text))
,"Title" 
,"Name"
,If(SortDescending1, SortOrder.Ascending, SortOrder.Descending)
)

 

poweractivate_0-1658556677440.png

See how 'descending' is attempted to be interpreted as a 'column'

 

So of course, "the specified column 'descending' does not exist" - which makes sense now, right?

 

The specified column 'descending' does not exist or is an invalid sort column type

 

poweractivate_3-1658556142120.png

So why does the error say

 

"the specified column 'descending' does not exist or is an invalid sort column type"?

 

I think the choice of words has an interesting effect here, because of the fact that the function SortByColumns happens to be dealing with columns and also "sort order", so it might be difficult to quickly glance at this error and even understand what is going on, and it might also easily be confounded with the sort order and give the impression that the error is complaining about the sort order, when interestingly enough, the error is actually complaining about the column (i.e. the 4th argument being a sort order where there should be a column)!

 

Likely, invalid sort column type here might simply mean that if the column happened to exist, Power Apps suspects that the column might not be a valid type of column that could be used for sorting with SortByColumns.

In other words, Power Apps does not know for sure whether the column really does not exist, or whether it does exist but is just not a valid kind of column that could be used in SortByColumns - so as a result, maybe that is why this particular error is worded in this way.

 

For your case, the first part of the error is most important:

 

the specified column 'descending' does not exist or is an invalid sort column type

 

The error is ultimately caused, by 'ascending' (or 'descending') being fed into a column argument!

 

That's why it says 

the specified column 'descending' does not exist

or 

the specified column 'ascending' does not exist

 

So since "the specified column does not exist", then the first thing you should do is check if you have put a SortOrder where you should have instead put the name of a column (which is what went wrong here).

 

Make sure that if you provide more than one column or multiple columns to SortByColumns, that every column is followed by a sort order, so column, order, column, order, etc.... After that, you can only optionally remove only the very last sort order for the very last column (i.e. the very last argument) - but you can remove nothing else. Then it should work correctly.

 

You can also apply the exact same rule even for just one column. You can either provide the column and the order, or just the column, and the one and only column will be that last column.

 

So just make sure to always specify a sort order after every single column, and after you've done that, you can optionally decide if you want to take the very last sort order out, or leave it in. You can not take out anything else. If you make sure to do this, you would be less likely to face this specific kind of issue again.

 

Check if this helps as well @hankycheng0621 

 

Thanks for your detailed help @poweractivate 
After try your 2 methods it's successful to search TicketNumber but fail if Name on the same searchBox. Is it a problem with my code? Thanks

SortByColumns(Filter(SiteLog, StartsWith(TicketNumber, TextSearchBox1.Text)), "Title", If(SortDescending1, SortOrder.Descending, SortOrder.Ascending), "field_9")

hankycheng0621_0-1658558363691.png

 

@hankycheng0621 

 

What is the error shown in the formula bar when you hover over it?

 

I think it is because the column is called something else, not "Name" in your case.

 

Try to find out what the column is really called that has the name of the ticket, and use that instead of "Name".

@poweractivate  it haven't error, just nothing happen if search "Name"

Filter(SiteLog, StartsWith(TicketNumber, TextSearchBox1.Text))

The Filter  is the only part of the formula that performs the search

You are only filtering on TicketNumber.

Everything else in the formula is from SortByColumns and only determines the order of how the returned results are displayed in the Gallery(the Gallery Items)

 

I'll see if I can tell you shortly how you should change the formula.

@hankycheng0621 

 

Try something like this instead:

 

SortByColumns(
    Filter(SiteLog,StartsWith(TicketNumber, TextSearchBox1.Text) || StartsWith(Name, TextSearchBox1.Text))
    ,"Title"    
    ,If(SortDescending1, SortOrder.Ascending, SortOrder.Descending)
    ,"Name"
    ,If(SortDescending1, SortOrder.Ascending, SortOrder.Descending)
    
)

 

 

Check new version of sample app app22b.msapp attached to this post as well in case it helps, with the new formula above in the app.

 

For more info on the Filter function, check on this guide:

Filter - docs.microsoft.com

 

Check if it helps @hankycheng0621 

@poweractivate  Thanks for help and give me more knowledge about the search and filter functions. Now I success create a search box with multi-column search now. thanks for your help again.

Remya-praveen
Frequent Visitor

Hi, I am unable to get the Search Box thing right from past couple of days. I have tried all available solutions something like the below format:  

Filter(SiteLog, StartsWith(TicketNumber, TextSearchBox1.Text))
 Search(IceCream, "choc", "Flavor")
Filter(Customers, SearchInput.Text in Name) etc.,


But none of them are not working. Is there something that I am doing wrong. Could anyone help me out in this. TIA

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!   This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions in the Forums to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersNumber of SolutionsSuper UsersNumber of Solutions @anandm08  23 @WarrenBelz  31 @DBO_DV  10 @Amik  19 AmínAA 6 @mmbr1606  12 @rzuber  4 @happyume  7 @Giraldoj  3@ANB 6 (tie)   @SpongYe  6 (tie)     Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersSolutionsSuper UsersSolutions @anandm08  10@WarrenBelz 25 @DBO_DV  6@mmbr1606 14 @AmínAA 4 @Amik  12 @royg  3 @ANB  10 @AllanDeCastro  2 @SunilPashikanti  5 @Michaelfp  2 @FLMike  5 @eduardo_izzo  2   Meekou 2   @rzuber  2   @Velegandla  2     @PowerPlatform-P  2   @Micaiah  2     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 3:Community MembersSolutionsSuper UsersSolutionsPower Apps anandm0861WarrenBelz86DBO_DV25Amik66Michaelfp13mmbr160647Giraldoj13FLMike31AmínAA13SpongYe27     Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 4:Community MembersSolutionsSuper UsersSolutionsPower Apps DBO-DV21WarranBelz26Giraldoj7mmbr160618Muzammmil_0695067Amik14samfawzi_acml6FLMike12tzuber6ANB8   SunilPashikanti8

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (1,644)