cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MShelnutt
Helper IV
Helper IV

SharePoint ID column

Hi,

 

I need to put a Filter or Search box in my PowerApp so the user can filter the Gallery by the ID column in my connected SharePoint list.

I found this formula on another post, but am not clear on what the "a" and "b" are:

 

Search(
       AddColumns(my_SP_List,"id2",Text(ID)), 
       TextSearchBox1.Text,
       "a", "b", "id2")

 

Any ideas?

Because I have 3 Search boxes:  By Customer Name or RMA#, by CC# {The ID column of SharePoint}, and by Status- so I need to have a Search function in my Gallery Items setting to allow for all three:

 

MShelnutt_1-1616500176335.png

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User III
Super User III

@MShelnutt 

You are adding new criteria to your search function on each reply.  

Again, The Search function takes 3 or more parameters.  The first is the datasource, the second is the text you want to search for (usually a reference to a textinput control) and the third (and subsequent) parameter are the columns in the datasource that you want to search.  They must be text columns.

You keep adding Text and then another column.  Search does not work that way.

Plus, the name of your TextInput control keeps changing each time.  Before it was NameRMABox and now it seems to be NameBox, or RMABox??

 

For EVERY different search criteria you have you have to separate into another Search function.

Your formula this go around should be this:

Search(                               // Search 2
    // datasource for Search 1 (the results of Search 1)
    Search(                           // Search 1
        // datasource for Search 1  (the results of the Filter)
        Filter('Customer Complaints 21',  // datasource for Filter
            // criteria for filter
            (IsBlank(CCBox.Text) || ID = Value(CCBox.Text)) &&
            (CountRows(FormStatusFilter.SelectedItems) = 0 || Form_x0020_Status in FormStatusFilter.SelectedItems.Value)
        ),
        NameBox.Text, "CustomerName"   // critieria and columns for Search 1
    ),
    RMABox.Text, "RMA_x0020_Number"    // criteria and columns for Search 2
)
    

 

So the way you read this is from the inside out.  

At the core of the formula is the Filter function.  It filters your datasource with the criteria provided.  The Filter returns a table of records.

 

That table of records becomes the first parameter of your Search function (search 1).  

So, if you look at the "signature" for search 1, it has the first parameter of the datasource (which is the results of the filter),  the second parameter of Search 1 is NameBox.Text, and the third parameter is "CustomerName".  Search returns a table of records.

 

That table of records becomes the first parameter of your next Search Function (Search 2)

So, if you look at the "signature" for search 2, it has the first parameter of the datasource (which is the results of Search 1),  the second parameter of Search 1 is RMABox.Text, and the third paramter is "RMA_x0020_Number".

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

View solution in original post

39 REPLIES 39
RandyHayes
Super User III
Super User III

@MShelnutt 

Pretty sure that a and b were just part of whatever you copied.

The Search function takes 3 or more parameters.  The first is the datasource, the second is the text you want to search for (usually a reference to a textinput control) and the third (and subsequent) parameter are the columns in the datasource that you want to search.  They must be text columns.

 

So, your formula should be:

Search(
    // Parameter 1
       AddColumns('Customer Complaints 21', "ID2", Text(ID)),
    // Parameter 2
       NameRMABox.Text,                      
    // Parameter 3
       "CustomerName",                       
    // Parameter 4
       "ID2"                                 
)

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

@RandyHayes 

I tried to follow, but it doesn't like it.

MShelnutt_0-1616507560556.png

It says the Search function has some invalid arguments.

And the 3rd line down, the 'Customer Complaints 21', has its own red line which says Invalid argument type (table). Expecting a text type instead.

 

 

RandyHayes
Super User III
Super User III

@MShelnutt 

Not sure you were following what I mentioned.

The Search function takes 3 or more parameters.  The first is the datasource, the second is the text you want to search for (usually a reference to a textinput control) and the third (and subsequent) parameter are the columns in the datasource that you want to search.  They must be text columns.

 

In your image you are trying to search by multiple sources, and you also are trying to filter by multiple values from the combobox.  This is highly different than initially posted.  So, this has to be broken down to each one.  Search does a search on a table based on a "Search text" and the columns you want to search on.  It does not allow multiple search criteria.

 

So, your formula should be:

Search(
    Filter('Customer Complaints 21', 
        ID = Value(CCBox.Text) &&
        Form_x0020_Status in FormStatusFilter.SelectedItems.Value
    ),
    NameRMABox.Text, "CustomerName"
)

 

There is no sense in converting the ID to text to search on it.  ID's are unique, so if you want to search by ID specifically from the CCBox.Text value, then you should do that as part of the filter.

Also, since you have multiple selections in your combobox (presumed based on your formula), then you need to utilize the "in" operator to get correct results.

So, in the above formula, these are all part of the filter.

Finally, all of those results are "fed" to the Search function as its first parameter (the datasource) and then we use the NameRMABox.Text to search the "CustomerName" column.

 

If for some reason you are doing a "partial" search (meaning that users might NOT put in certain criteria for searching) then you can make your formula more dynamic to that with this:

Search(
    Filter('Customer Complaints 21', 
        (IsBlank(CCBox.Text) || ID = Value(CCBox.Text)) &&
        (CountRows(FormStatusFilter.SelectedItems) = 0 || Form_x0020_Status in FormStatusFilter.SelectedItems.Value)
    ),
    NameRMABox.Text, "CustomerName"
)

This will provide the user the ability to enter "some" of the criteria and still get results.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

@RandyHayes 

I don't know why I have such a hard time with these formulas.

I had to split one of the boxes into two search boxes and renamed accordingly.  

Your first offer looks like this-

MShelnutt_1-1616510747433.png

 

 

Your second offer looks like this-

MShelnutt_0-1616510681991.png

What am I doing wrong?

 

MShelnutt_0-1616511346704.png

 

RandyHayes
Super User III
Super User III

@MShelnutt 

You are adding new criteria to your search function on each reply.  

Again, The Search function takes 3 or more parameters.  The first is the datasource, the second is the text you want to search for (usually a reference to a textinput control) and the third (and subsequent) parameter are the columns in the datasource that you want to search.  They must be text columns.

You keep adding Text and then another column.  Search does not work that way.

Plus, the name of your TextInput control keeps changing each time.  Before it was NameRMABox and now it seems to be NameBox, or RMABox??

 

For EVERY different search criteria you have you have to separate into another Search function.

Your formula this go around should be this:

Search(                               // Search 2
    // datasource for Search 1 (the results of Search 1)
    Search(                           // Search 1
        // datasource for Search 1  (the results of the Filter)
        Filter('Customer Complaints 21',  // datasource for Filter
            // criteria for filter
            (IsBlank(CCBox.Text) || ID = Value(CCBox.Text)) &&
            (CountRows(FormStatusFilter.SelectedItems) = 0 || Form_x0020_Status in FormStatusFilter.SelectedItems.Value)
        ),
        NameBox.Text, "CustomerName"   // critieria and columns for Search 1
    ),
    RMABox.Text, "RMA_x0020_Number"    // criteria and columns for Search 2
)
    

 

So the way you read this is from the inside out.  

At the core of the formula is the Filter function.  It filters your datasource with the criteria provided.  The Filter returns a table of records.

 

That table of records becomes the first parameter of your Search function (search 1).  

So, if you look at the "signature" for search 1, it has the first parameter of the datasource (which is the results of the filter),  the second parameter of Search 1 is NameBox.Text, and the third parameter is "CustomerName".  Search returns a table of records.

 

That table of records becomes the first parameter of your next Search Function (Search 2)

So, if you look at the "signature" for search 2, it has the first parameter of the datasource (which is the results of Search 1),  the second parameter of Search 1 is RMABox.Text, and the third paramter is "RMA_x0020_Number".

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

View solution in original post

@RandyHayes 

I apologize if I am not being clear with my actions.  I stated in the previous response that I had a search box called nameRMAbox... which was intended to search 2 columns in my SP list.  I decided for simplicity to separate them into 2 separate search boxes- Name and RMA.  But all that meant was an additional line of search formula.

 

But regardless, the only thing I see missing in my formula from your last suggestion is a closing parenthesis.

Do I need to enter the Data Source for each line?  I only have one data source- 'Customer Complaints 21'.

 

Now the formula does not like the comma after it-

MShelnutt_0-1616512780943.png

MShelnutt_1-1616513010684.png

 

 

@RandyHayes 

I just realized you entered another Search(...

So I added that and it seems to like it-

MShelnutt_2-1616513467162.png

But, none of the search functions are working when I play the app.  The Gallery is missing altogether.

RandyHayes
Super User III
Super User III

@MShelnutt 

In the formula I provided, you have 3 datasources -

The first is 'Customer Complaints 21' - it is a table of records (it just happens to be from your underlying data source)

The second datasource is the results of Filter - it is a table of records returned from Filter.

The third datasource is the results of Search 1 - it is a table of records returned from Search

 

This formula I provided is correct:

Search(                               // Search 2
    // datasource for Search 1 (the results of Search 1)
    Search(                           // Search 1
        // datasource for Search 1  (the results of the Filter)
        Filter('Customer Complaints 21',  // datasource for Filter
            // criteria for filter
            (IsBlank(CCBox.Text) || ID = Value(CCBox.Text)) &&
            (CountRows(FormStatusFilter.SelectedItems) = 0 || Form_x0020_Status in FormStatusFilter.SelectedItems.Value)
        ),
        NameBox.Text, "CustomerName"   // critieria and columns for Search 1
    ),
    RMABox.Text, "RMA_x0020_Number"    // criteria and columns for Search 2
)

 

This formula is NOT:

RandyHayes_0-1616513730055.png

You only have one Search function in it with an extraneous set of text and columns.  Please copy and paste the formula I provided above.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes
RandyHayes
Super User III
Super User III

@MShelnutt 

Cross-post - yes, there have to be separate search function for each search criteria.

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Did you miss the call? Check out the recording here!

Top Solution Authors
Top Kudoed Authors
Users online (19,962)