cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Brank
Level 8

Search with the table result of other search

Hello, I was trying to do multiple search in one button, considering that if the search is not found it return all the records, this would be usefull for do a search with multiple parameters. For example in my case I have 2 parameters for search in the table, lets say:

parameter1, parameter2.

I want to do the next:

 

Search(Search('Data source'; String1.Text; Parameter1); String2.Text; Parameter2)

 

In theory I would get all the records that satisfy parameter1 = String1.Text && parameter2 = String2.Text, if doesnt satisfy parameter1 but it does in parameter2 I would get all the records that satisfy parameter2 but in my case I got nothing. It seems I cannot use the result of the first Search as parameter of the second one even though the result is a table with records (that acts the same as a Data source). As an alternative I am doing right now 2^2 = 4 "if" sentences but this isn't scalable at all because if I got 6 parameters I would get 2^6 = 64 "if" sentences, thats why I want to use the search function.

 

Is this a bug or I just don't understand well the functionality of search?

 

If you have any doubts about what I am trying to explain I would answer thankfully.

 

Regards,

1 ACCEPTED SOLUTION

Accepted Solutions
Meneghino
Level 10

Re: Search with the table result of other search

PPS The caching will work only for sources with up to 500 rows.  If you have more than 500 lines then use this:
https://powerusers.microsoft.com/t5/PowerApps-Forum/500-item-limit-in-CDM-entity-search-filter-need-...

 

My solution is towards the end of the post

View solution in original post

12 REPLIES 12
Meneghino
Level 10

Re: Search with the table result of other search

Hi @Brank

 

Could you please clarify what Parameter1 and Parameter2 are?  Are they two different text fields in 'Data source'?

 

Assuming this is the case, what is the result you are looking for?
1) To satisfy parameter1 = String1.Text && parameter2 = String2.Text etc. etc.

OR

2) To satisfy parameter1 = String1.Text || parameter2 = String2.Text etc. etc.

 

Finally, are you looking to match letter cases or not?

 

Thanks.

 

Brank
Level 8

Re: Search with the table result of other search

Hello @Meneghino,

Parameter1 and Parameter2 in this case are Columns in the table of the data source. As we know the "data source" can be an external data source (Common data service, SQL Server, etc) or tables. Lets say 'Data source' is an entity in the Common data service, this entity has the next columns:

 

Parameter 1                     l      Parameter2

---------------------------------------------------------

Parameter value 1           l     Parameter value 2

Parameter value 3           l      Parameter value 4

 

Lets say I do: 

UpdateContext({firstSearch : Search('Data source'; "Parameter value"; Parameter 1) })  In this case the variable context "firstSearch" will have a table with all the records because in the parameter 1 I have 2 records that start with "Parameter value" then I want to do:

 

UpdateContext({secondSearch : Search(firstSearch; "Parameter value 4"; Parameter 2)}) In this case I will get in the variable context "secondSearch" a table with just the second record because Parameter 2 has "Parameter value 4". But in my case the secondSearch variable has an empty table.

 

Regards,

Meneghino
Level 10

Re: Search with the table result of other search

Ok, I think I understand what you need.  For example:

 

Filter('Data source', String1.Text in Parameter1 || String2.Text in Parameter1, String3.Text in Parameter2 || String4.Text in Parameter2)

You can combine as you like and use 'exactin' instead of 'in' if you need to match case

Brank
Level 8

Re: Search with the table result of other search

Hi @Meneghino,

The problem is that Filter doesn't return all the records if one of the Strings.Text is blank, it would just don't return any records because it doesn't satisfy the condition.

 

Regards,

Meneghino
Level 10

Re: Search with the table result of other search

Ok, you are right.  "" will return all records but a null value will not.

Use this for all the tests of the Filter:

 

(IsBlank(MySearchText) || MySearchText in TargetTextField)

Please let me know how you get on

Brank
Level 8

Re: Search with the table result of other search

I think you didn't undertand why I want to use Search instead of Filter. Smiley Surprised

If I used Filter I have to do 2^numberOfParameters Filters with If senteces for know if one of the parameters string is Blank or not because the Filter function will change in everycase.

 

 

Meneghino
Level 10

Re: Search with the table result of other search

OK, it works, so I think you must have something wrong in your syntax.  By the way, I would always avoid the use of spaces in column names. If you do have spaces, then you may need to wrap them in single quotes 'Parameter 1' etc.

Please note below that because you are in a different locale, you will need to substitute some , with ; and the ; with ;;

 

Here are the steps:

  1. Create Gallery1 with Items property as follows:
    Table({Parameter1: "Parameter value 1", Parameter2: "Parameter value 2"}, {Parameter1: "Parameter value 3", Parameter2: "Parameter value 4"})
  2. Create a button with OnSelect property as follows:
    UpdateContext({firstSearch : Search(Gallery1.AllItems, "Parameter value", "Parameter1") });
    UpdateContext({secondSearch : Search(firstSearch, "Parameter value 4", "Parameter2")})   
  3. Create a gallery with Items property as follows:
    secondSearch

Please let me know how you get on.

 

__.JPG

Brank
Level 8

Re: Search with the table result of other search

I see what you did there!

I have no errors in syntax, the only difference between yours and mine is that I am doing the search with a data source using "Common Data Service", can you replace the in the first search the "Gallery1.AllItems" for data source in Common Data Service?.

 

Thanks in advance.

 

Regards,

Meneghino
Level 10

Re: Search with the table result of other search

Hi @Brank, this may be a problem of delegation.

 

What you can try is to substitute this for the button OnSelect and eliminate Gallery1:

ClearCollect(CachedDataSource, 'Data source');
UpdateContext({firstSearch : Search(CachedDataSource, "Parameter value", "Parameter1") });
UpdateContext({secondSearch : Search(firstSearch, "Parameter value 4", "Parameter2")})   

Please let me know.

 

PS I use caching often also for perfomance purposes.  If the source does not change often you can just cache once after the user starts the app.  I do this by having a welcome screen and a "Proceed" button that caches all necessary tabels and then navigates to the first real screen of the app

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (4,663)