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

Filter Collection Where Alias Contains

Hi All. 
I have a variable set to obtain the current logged in user's alias by splitting the email address and returning only the left value by delimiter. The formula alias formula works and is as followed:

Set(_UserEmail, User().Email);
Set(_UserAlias, Lower(First(Split(_UserEmail, "@")).Result));


I then have a collection called UserList with a column called Reviewer which has a large range of users. Inside this large list I want to create a new collection where my alias is equal to any record inside Userlist. My current formula is this which gives me no error nor does it return any results:

ClearCollect(_MyAccess, Filter(UserList, _UserAlias in Lower(Reviewer.Email)));

Sample Data for UserList:

IDReviewer
1ME@Company.com
 Person1@Company.com
 Person2@Company.com
 Person3@Company.com
 Person4@Company.com
2ME@Company.com
3Person1@Company.com
 Person2@Company.com
 Person3@Company.com

 

Sample Result for _MyAccess:

IDReviewer
1ME@Company.com
 Person1@Company.com
 Person2@Company.com
 Person3@Company.com
 Person4@Company.com
2ME@Company.com


Any help would be greatly appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Filter Collection Where Alias Contains

@hnguy71 

Can you explain why you would expect two records from that formula?

My assumption is that you would expect ID 1 and 2 to be in your collection - however, you will not get that because I believe you have a typo in your formula for ID 2.  There you have ME@CompanyB.com - again, my assumption is that you wanted that to be ME@CompanyA.com

 

IF the above is correct that it was wrong, then your formula needs to adjust to this in order to get the results that you want:

Set(gvUserEmail, "Me@CompanyA.com");
ClearCollect(
    colUserList,
    {
        ID: 1,
        Review: Table(
            {Name: "Myself", Email: "ME@CompanyA.com"},
            {Name: "Person1", Email: "Person1@CompanyB.com"},
            {Name: "Person2", Email: "Person2@CompanyA.com"},
            {Name: "Person3", Email: "Person3@CompanyA.com"},
            {Name: "Person4", Email: "Person4@CompanyB.com"}
        )
    },
    {
        ID: 2,
        Review: Table({Name: "Myself", Email: "ME@CompanyA.com"})
    },
    {
        ID: 3,
        Review: Table(
            {Name: "Person1", Email: "Person1@CompanyA.com"},
            {Name: "Person2", Email: "Person2@CompanyB.com"},
            {Name: "Person3", Email: "Person3@CompanyB.com"}
        )
    }
);
ClearCollect(
    colMyAccess, 
    Filter(
Ungroup(colUserList, "Review"),
gvUserEmail in Lower(Email)
) )

You need to ungroup the table to be able to filter on it like that.

 

I hope that is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
6 REPLIES 6
Super User
Super User

Re: Filter Collection Where Alias Contains

I see a couple of concerns with the example you provided. The "in" operator is trying to match the UserAlias value with the full email address in the Review column. The second concern is the "Reviewer.Email" when I think you really want to see if the UserAlias is in the list of email address in the "Reviewer" column for each row.

Here is an example that I think accomplishes what you are trying to do. The two big changes here are I am using the user's email address to compare against the Reviewer field since it contains complete email addresses and then I am comparing against the Reviwer column and not Reviewer.Email.

The "Set()" and "ClearCollect()" and just setting up my sample data to match your use case. You should be able to cut and paste this example into a button and test it out. If it works for you then you should be able to make some minor tweaks to it to get it to work in your app.

 

Set(gvUserEmail, "Me@Company.com");
ClearCollect(
    colUserList,
    {
        ID: 1,
        Review: Table(
            {Email: "ME@Company.com"},
            {Email: "Person1@Company.com"},
            {Email: "Person2@Company.com"},
            {Email: "Person3@Company.com"},
            {Email: "Person4@Company.com"}
        )
    },
    {
        ID: 2,
        Review: Table({Email: "ME@Company.com"})
    },
    {
        ID: 3,
        Review: Table(
            {Email: "Person1@Company.com"},
            {Email: "Person2@Company.com"},
            {Email: "Person3@Company.com"}
        )
    }
);
ClearCollect(
    colMyAccess,
    Filter(
        colUserList,
        gvUserEmail in Lower(Review)
    )
)


--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.
hnguy71
Level 8

Re: Filter Collection Where Alias Contains

Hi @Jeff_Thorpe ,
Thanks for the reply!
Originally I had a similar code to match by the full email address. The issue is that each person can have alternate email addresses which sometimes doesn't pick up. However, their alias (email nick) always remains the same regardless of which email account they're using. To extend your solution that mimics my table I'm expecting the new collection to return two records:

Set(gvUserEmail, "Me@CompanyA.com");
ClearCollect(
    colUserList,
    {
        ID: 1,
        Review: Table(
            {Name: "Myself", Email: "ME@CompanyA.com"},
            {Name: "Person1", Email: "Person1@CompanyB.com"},
            {Name: "Person2", Email: "Person2@CompanyA.com"},
            {Name: "Person3", Email: "Person3@CompanyA.com"},
            {Name: "Person4", Email: "Person4@CompanyB.com"}
        )
    },
    {
        ID: 2,
        Review: Table({Name: "Myself", Email: "ME@CompanyB.com"})
    },
    {
        ID: 3,
        Review: Table(
            {Name: "Person1", Email: "Person1@CompanyA.com"},
            {Name: "Person2", Email: "Person2@CompanyB.com"},
            {Name: "Person3", Email: "Person3@CompanyB.com"}
        )
    }
);
ClearCollect(
    colMyAccess,
    Filter(
        colUserList,
        gvUserEmail in Lower(Review.Email)
    )
)
Super User
Super User

Re: Filter Collection Where Alias Contains

@hnguy71 

Can you explain why you would expect two records from that formula?

My assumption is that you would expect ID 1 and 2 to be in your collection - however, you will not get that because I believe you have a typo in your formula for ID 2.  There you have ME@CompanyB.com - again, my assumption is that you wanted that to be ME@CompanyA.com

 

IF the above is correct that it was wrong, then your formula needs to adjust to this in order to get the results that you want:

Set(gvUserEmail, "Me@CompanyA.com");
ClearCollect(
    colUserList,
    {
        ID: 1,
        Review: Table(
            {Name: "Myself", Email: "ME@CompanyA.com"},
            {Name: "Person1", Email: "Person1@CompanyB.com"},
            {Name: "Person2", Email: "Person2@CompanyA.com"},
            {Name: "Person3", Email: "Person3@CompanyA.com"},
            {Name: "Person4", Email: "Person4@CompanyB.com"}
        )
    },
    {
        ID: 2,
        Review: Table({Name: "Myself", Email: "ME@CompanyA.com"})
    },
    {
        ID: 3,
        Review: Table(
            {Name: "Person1", Email: "Person1@CompanyA.com"},
            {Name: "Person2", Email: "Person2@CompanyB.com"},
            {Name: "Person3", Email: "Person3@CompanyB.com"}
        )
    }
);
ClearCollect(
    colMyAccess, 
    Filter(
Ungroup(colUserList, "Review"),
gvUserEmail in Lower(Email)
) )

You need to ungroup the table to be able to filter on it like that.

 

I hope that is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
hnguy71
Level 8

Re: Filter Collection Where Alias Contains

Hi @RandyHayes 

Sorry for the misunderstanding. The email in ID 2 is correct. I'd like to evaluate if the alias / mailnick is the same regardless of email domain name. So Me@CompanyA.com should also return true if Me@CompanyB.com.  Ungrouping them did the trick! 

 

Could you explain why ungrouping them would work versus just leaving them inside a table?

Super User
Super User

Re: Filter Collection Where Alias Contains

@hnguy71 

Glad to hear that worked.

The reason the ungrouping worked for you is that your filter is applying to a set of records.  Since the table is an element within the records, you just need to get it to a state where there are records that you can filter against. 

When you ungroup, you are creating a table of records, one for each record in the sub table.  This can then be easily filtered.  

If you put the ungrouped collection into another collection, you can see the results...and those are a table of all the records with their corresponding "main" record elements.  That satisfies the filter function much better.

 

I hope that is clear...I re-read it and I'm wondering if I am stating the point properly.  Best thing to do is to throw the ungrouped collection into something you can see in the Collection Viewer or in a Gallery.  That will make more sense.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Highlighted
hnguy71
Level 8

Re: Filter Collection Where Alias Contains

Yep that explanation definitely helped. Thaks a lot for the help as always!

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

SecondImage

Follow PowerApps on Twitter

Stay Up-to-Date by following PowerApps on Twitter

Top Community Contributors for July 2019

Top Community Contributors for July 2019

Let's thank our top community contributors

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

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

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

FifthImage

Dynamics 365 and Power Platform April 2019 Release notes

Features releasing from April 2019 through September 2019!

Users Online
Currently online: 73 members 4,097 guests
Please welcome our newest community members: