cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Buddy2019
Helper I
Helper I

Forall on collection with isMatch()

I am trying to use a ForAll on a collection called TestInfo that will check if the "Time" column will match "5:00".

 

I tried

ForAll(TestInfo, IsMatch(TestInfo.Time, "3:00")).

 

Error Message says "Invalid argument type (table). Expecting a Text value instead". How would i get the text value of the collection items and does the Forall return a new table with a true and false values ?

 

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

Hi @Buddy2019 ,

Could you please share a bit more about your scenario?

Do you want to detect if the time value within the Time column in your TestInfo collection match "5:00"?

 

Based on the screenshot that you provided, I think the Time column (in your TestInfo collection) contains a Table value. So the result the TestInfo.Time formula returned is a Table value rather than Text value. But the first argument of the IsMatch function is required to provide a Text value.

 

I have made a test on my side, please take a try with the following workaround:8.JPG

 

9.JPG

 

10.JPG

Set the OnStart property of the App control to following:

 

ClearCollect(
             TestInfo,
             {ProductName: "PowerApps", Time: Table({StartTime: "07/26/2019 3:00 PM"}, {StartTime: "07/26/2019 12:00 PM"})},
             {ProductName: "MS Flow", Time: Table({StartTime: "07/26/2019 5:00 PM"}, {StartTime: "07/26/2019 6:00 PM"})}
)

The TestInfo data structure as below:13.JPG

 

Set the OnSelect property fo the "Execute Match" button to following (nested ForAll functions):

ForAll(
       TestInfo,
       ForAll(
              Time,
              If(
                  IsMatch(StartTime, "\d{1,2}\/\d{1,2}\/\d{4} 5:00 (AM|PM)"),
                  Collect(MatchRecords, {ProductName: ProductName, MatchedTime: StartTime})
              )
        )
)

On your side, you may type following:

ForAll(
       TestInfo,
       ForAll(
              Time,
              If(
                  IsMatch(StartTime, "\d{1,2}\/\d{1,2}\/\d{4} 5:00 (AM|PM)"),
                  Collect(
MatchRecords,
{
Column1: Column1,
Column2: Column2,
...
MatchedTime: StartTime
}
) ) ) )

Note: The Column1, Column2, ... represents the columns in your TestInfo collection.

Add a Data Table control, set the Items proeprty to following:

MatchRecords

When you press the "Execute Match" button, above Data Table control would be populated with matched records and corresponding matched time.

 

Best regards,

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
timl
Super User III
Super User III

Hi @Buddy2019 

In answer to your question, the ForAll function doesn't return a table with true and false values. To do this, you can use the AddColumns function rather than ForAll. The syntax would look like this:

 

AddColumns(TestInfo, 
"TimeMatch",
IsMatch(Time, "5:00")
)

This function returns a table with a new column called TimeMatch. The field value will be true when the time matches 5:00.

The Concat function can help you extract text values from a table. There are more details here.

https://docs.microsoft.com/en-gb/powerapps/maker/canvas-apps/functions/function-concatenate

 

 

 

 

RezaDorrani
Dual Super User II
Dual Super User II

Hi @Buddy2019 

 

Try the following code:

 

ForAll(TestInfo, If(IsMatch(Text(TestInfo[@StartTime]), "3:00",MatchOptions.Contains),Collect(newcollection,TestInfo[@StartTime])))

 

ForAll does not create a new collection, you would have to create one withing ForAll

The above example will create a new collection for you

 

Regards,

Reza Dorrani

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

v-xida-msft
Community Support
Community Support

Hi @Buddy2019 ,

Could you please share a bit more about your scenario?

Do you want to detect if the time value within the Time column in your TestInfo collection match "5:00"?

 

Based on the screenshot that you provided, I think the Time column (in your TestInfo collection) contains a Table value. So the result the TestInfo.Time formula returned is a Table value rather than Text value. But the first argument of the IsMatch function is required to provide a Text value.

 

I have made a test on my side, please take a try with the following workaround:8.JPG

 

9.JPG

 

10.JPG

Set the OnStart property of the App control to following:

 

ClearCollect(
             TestInfo,
             {ProductName: "PowerApps", Time: Table({StartTime: "07/26/2019 3:00 PM"}, {StartTime: "07/26/2019 12:00 PM"})},
             {ProductName: "MS Flow", Time: Table({StartTime: "07/26/2019 5:00 PM"}, {StartTime: "07/26/2019 6:00 PM"})}
)

The TestInfo data structure as below:13.JPG

 

Set the OnSelect property fo the "Execute Match" button to following (nested ForAll functions):

ForAll(
       TestInfo,
       ForAll(
              Time,
              If(
                  IsMatch(StartTime, "\d{1,2}\/\d{1,2}\/\d{4} 5:00 (AM|PM)"),
                  Collect(MatchRecords, {ProductName: ProductName, MatchedTime: StartTime})
              )
        )
)

On your side, you may type following:

ForAll(
       TestInfo,
       ForAll(
              Time,
              If(
                  IsMatch(StartTime, "\d{1,2}\/\d{1,2}\/\d{4} 5:00 (AM|PM)"),
                  Collect(
MatchRecords,
{
Column1: Column1,
Column2: Column2,
...
MatchedTime: StartTime
}
) ) ) )

Note: The Column1, Column2, ... represents the columns in your TestInfo collection.

Add a Data Table control, set the Items proeprty to following:

MatchRecords

When you press the "Execute Match" button, above Data Table control would be populated with matched records and corresponding matched time.

 

Best regards,

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

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

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

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

Top Solution Authors
Top Kudoed Authors
Users online (46,677)