cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MaxDonen
Level: Powered On

Check if string in collection matches another string plus an extra character

I have two strings in a collection column (eg) 1,4 and 1,4,2. 

 

I want to check if:

1) the second string starts with the first string 

2) the second string subsequently includes a comma and a digit. 

 

Here's my attempt, which caused no errors but did not work correctly:

 

 thisitem.ID_Number=thisitem.ID_Number&","&Digit

 

using text() to wrap the above also did not help (but didn't cause any errors, either)

 

I also tried isMatch(ID_Number, thisitem.ID_Number...) (this in itself caused an issue, without the comma/digit condition, as it seems to be incorrect syntax to use on a collection. I have been advised against using isMatch() before on collections so would rather not use this method. 

 

 

Can anyone assist?

 

Thanks!

 

 

4 REPLIES 4
PowerApps Staff Mr-Dang-MSFT
PowerApps Staff

Re: Check if string in collection matches another string plus an extra character

I like text manipulation questions 🤓

 

It looks like you want to compare one string to another to see what is shared or not shared.

 

Can you clarify:

  • Where are these strings coming from (it was unclear)? Are both of these strings coming from the different columns of a single record? Are the strings coming from different records?
Community Support Team
Community Support Team

Re: Check if string in collection matches another string plus an extra character

Hi @MaxDonen ,

Could you tell me

1)where do 1,4 and 1,4,2 come from? Do they come from the same record, different fields?

2)the data type of 1,4 and 1,4,2?

I assume that they come from the same record, different fields, they are text type.

I've made a similar test for your reference:

Here's my collection:

ClearCollect(test,{ID_Number:"1,4",secondID:"1,4,2."})

Here's my justifiction formula:

If(StartsWith(ThisItem.secondID,ThisItem.ID_Number)&&
"," in Substitute(ThisItem.secondID,ThisItem.ID_Number,"")&&
"." in Substitute(ThisItem.secondID,ThisItem.ID_Number,""),
true,false)

10182.PNG

 

 

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
MaxDonen
Level: Powered On

Re: Check if string in collection matches another string plus an extra character

Hi @v-yutliu-msft  @mrQ , thanks for the response and sorry for the delay in replying.

 

<blockquote>

1)where do 1,4 and 1,4,2 come from? Do they come from the same record, different fields?

</blockquote>

They come from the same collection.

The collection is called 'Col_Media_AirportData1' and the column (same in both cases) is 'ID_Number'.

<blockquote>

2)the data type of 1,4 and 1,4,2?

</blockquote>

They are both strings. Do note, however, that I am trying to avoid periods at the end of any of the strings, as this would complicate data entry.

 

The purpose of requiring the strings to be checked is to evaluate items within a dropdown to see if they have any 'children'. So, to expand on my original example, consider the set of data below:

 

4,1

4,2

4,2,2

4,3

4,3,2

5

6

6,2

 

Here, 4,2 is a parent of 4,2,2

4,3 is a parent of 4,3,2

5 is an ultimate child, since it has no children.

6 is a parent of 6,2

6,2 is also an ultimate child.

 

My approach is trying to identify whether a string matches another plus an extra character (a comma in this case).

 

So "6,2" contains a comma, and therefore ("6" plus comma) matches "6,2" given this condition/requirement. Thus, "6" is a parent of "6,2".

 

("5" plus comma) does not match any other strings and is therefore an ultimate child.

 

Likewise, ("6,2" plus comma)  does not match any other strings and is therefore also an ultimate child.

 

I tried to follow your example, but your approach has the values in separate rows. Apologies for not making this issue clear; my values are all contained in 1 column. This means that the syntax below can't work in my case.

 

Thanks for the help so far-is there any way I can achieve this aim?

 

 

 

 

PowerApps Staff Mr-Dang-MSFT
PowerApps Staff

Re: Check if string in collection matches another string plus an extra character

Updated understanding:

It sounds like you would like a string from one record in a collection, e.g. 1,2,4, to be checked with another string from the same collection.

 

My first thought is that before you proceed with text manipulation, I am wondering if your problem may be better addressed in your data architecture. Currently, you include parent and child content together. Have you considered separating the parent content in one table and relating the child rows to it? It may be easier to 

 

Collection1: Parent records only

Collection2: Child records only

 

Below is what you might try with your current setup though.

 

Suppose you have a dropdown with 1,4 selected. 

You expect 1,4,2 to appear as its child.

 

You can retrieve all the children this way:

Filter(Col_Media_AirportData1, StartsWith(ID_Number, Dropdown.Selected.Value))

This means, "Filter the Col_Media_AirportData1 collection to get all the records whose ID_Number start with what is selected in the dropdown menu."

 

So 1,4 will return 1,4,2 and 1,4,4 since they both include 1,4.

 

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 (5,312)