cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MaxEgn
Frequent Visitor

Filter using LookUp and IsMatch from a Collection

Hello All!

 

I am trying to simplify a potentially huge nested If block of code for filtering data in a gallery.

In my database, [dbo].[Master] ,  each record has a field called “RouteNumber”.

Now I have roughly 15 users, and each user needs to see different records.  Therefore I need my “Gallery_1” to filter each record based on both my variable “CurrentUserName” and the route numbers associated with that user. 

For example:

 I created a local collection with each user and their routes.

ClearCollect(varUserInfo,

 { Name: “User1”,
eRouteNumber: “1, 3, 5, 7, 9”}

 

{Name: “User2”,
eRouteNumber: “2, 4, 6, 8, 10”}
);

 

I need to Filter my Master data such that when User 2 is logged in,  the gallery shows all records that contain one of the “eRouteNumbers” for that user (2 or 4 or 6 or 8 or 10).

 

I was attempting to use filter and LookUp to accomplish this, but I’m struggling greatly. 

Two methods I tried were creating “eRouteNumber” as a table to search through, but I would get a record instead of a text or boolian.  The other was to combine LookUp and IsMatch to see if I could get MatchOptions.Contain to validate the records.

 

Filter('[dbo].[Master]',

        LookUp(UsertInfo,

             Text(Name) = varCurrentUser, 

             IsMatch(Text(RouteNumber), Search(UserInfo, Text(RouteNumber), "eRouteNumber"), MatchOptions.Contains))

 

I hope this makes some sort of sense. I'm very happy to provide more information if I missed some things!

Thanks

 For Visibility, @RandyHayes , @mdevaney 

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User III
Super User III

@MaxEgn 

Perhaps consider something similar to this Formula:

With({routes: ForAll(
                   Split(LookUp(varUserInfo, Name="userName", eRouteNumber), ",")
                   Value(Result)
              )},
    Filter('[dbo].[Master],
        RouteNumber in routes
    )
)

Replace "userName" with the user name you have.

Assumption that RouteNumber is numeric.

 

This should give you what you are looking for.

 

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

View solution in original post

1 REPLY 1
RandyHayes
Super User III
Super User III

@MaxEgn 

Perhaps consider something similar to this Formula:

With({routes: ForAll(
                   Split(LookUp(varUserInfo, Name="userName", eRouteNumber), ",")
                   Value(Result)
              )},
    Filter('[dbo].[Master],
        RouteNumber in routes
    )
)

Replace "userName" with the user name you have.

Assumption that RouteNumber is numeric.

 

This should give you what you are looking for.

 

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

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

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 (18,759)