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

Filter by email and only return first result

Dear PowerApps Community

 

I have a SP list with the columns "Title", "employee", "date" and "manager".
This list contains many items with the same employee and manager.

 

In Powerapps, I'd like to show only one entry per employee in a gallery.

 

The idea is to have an employee list filtered to the currently logged in user (manager). Since I don't want to see duplicate employees I need to have this filtered, somehow. I guess the distinct function is the right one for this. However, since I need to access the "date" field as well, how do I achieve that?

12 REPLIES 12
Anonymous
Not applicable

Re: Filter by email and only return first result

Hello @isabasu,

 

Can you tell us more about your "manager" filed please ? 

Is it a name ? Is it a mail adress ?

 

After the filter you do, you can just as you said use the distinct function like that

Distinct(FutureFilterSource, Employee)

Keep me informed.

 

Thank you

isabasu
Level: Powered On

Re: Filter by email and only return first result

Hi @Anonymous 

 

Thanks for your help so far.

 

The employee and the manager field are people picker fields.

I'd like to filter and distinct in one Gallery at the same time. If I do distinct, I'll only get one field back.

Super User
Super User

Re: Filter by email and only return first result

@isabasu 

 

Can you try out the below expression:
 
AddColumns(GroupBy(Filter(SPListName, manager = User().Email),"employee","grouped"),"manager",First(grouped).manager,"date",First(grouped).Date,"Title",First(grouped).Title)
 
Now, when you want to access the details you can simply use the same column names as per your SP list and this will get only one record per manager and employee.
 
Hope this Helps!
 
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!
Anonymous
Not applicable

Re: Filter by email and only return first result

Hey,

 

If I understand rightly, you can process like this (assuming that manager filed is the full name) :

Distinct(
    Filter(
       DataSource,
Manager = User().FullName
),
Employee
)

Good for you ?

 

BR,

 

Louis

Community Support Team
Community Support Team

Re: Filter by email and only return first result

Hi @isabasu ,

Do you want to filter your Employees List based on current login user in manager column, and only display one entry per Employee within the Gallery?

 

Based on the issue that you mentioned, I think the combination of Filter function, GroupBy function and AddColumns function could achieve your needs.

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

Set the Items property of the Gallery to following formula:

DropColumns(
            AddColumns(
                    GroupBy(
                              Filter(
                                      'YourEmployeeList',
                                       manager.Email = User().Email
                              ),
                              "employee",
                              "GroupData"
                    ),
                   "Title",
                   First(GroupData).Title,
                   "date",
                  First(GroupData).date
                  "manager",
                  First(GroupData).manager
            ),
           "GroupData"
)

Then you could display employee, Title, date and manager column value in one entry per employee in your Gallery.

 

Above formula may cause a Delegation warning issue (the Pesson type column could not be delegated within SP connector), if the amount of your SP List records is not more than 2000, you could ignore this warning issue.

If the amount of your SP List records is not more than 2000, please take a try with the following workaround:

1. Set the "Data row limits for Non-delegable queries" option to maximum value -- 2000 within Advanced settings of App settings of your app.

2. Set the OnStart property of the App control to following:

ClearCollect(RecordsCollection, 'YourEmployeeList')

3. Modify above formula within the Items property of the Gallery as below:

DropColumns(
            AddColumns(
                    GroupBy(
                              Filter(
                                       RecordsCollection,
                                       manager.Email = User().Email
                              ),
                              "employee",
                              "GroupData"
                    ),
                   "Title",
                   First(GroupData).Title,
                   "date",
                  First(GroupData).date
                  "manager",
                  First(GroupData).manager
            ),
           "GroupData"
)

 

In addition, if the amount of your SP List records is more than 2000, please check and see the alternative solution within the following thread would help in your scenario:

https://powerusers.microsoft.com/t5/General-Discussion/Pulling-in-large-ish-SQL-tables/m-p/243777#M7...

 

More details about Delegation in PowerApps, please check the following article:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/delegation-overview

 

Please take a try with above solution, then check if the issue is solved.

 

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.
isabasu
Level: Powered On

Re: Filter by email and only return first result

@v-xida-msft 

Thanks for your in-depth answer.

 

I applied your method, but couldn't get it to work yet. One thing I have to mention to not confuse you completely is that "manager" is actually "responsible" and "date" is "endprobationperiod" :-). This is what I have so far:

 

DropColumns(
    AddColumns(
        GroupBy(
            Filter(
                'Tasks LM',
                responsible.Email = User().Email
            ),
            "{Name}",
            "GroupData"
        ),
        "employee",
        First(GroupData).employee,
        "Title",
        First(GroupData).Title,
        "endprobationperiod",
        First(GroupData).endprobationperiod,
        "responsible",
        First(GroupData).responsible
    ),
    "GroupData"
)

And this is what I see... 

gallrey.png

 

There is only one entry of the last in the gallery (the one ending with "ti" in the list. That is why it is only showing one. Otherwise there would be as many as for the other employee ending with "et".

Community Support Team
Community Support Team

Re: Filter by email and only return first result

Hi @isabasu ,

Do you group your filtered result by the '{Name}' column? Based on the formula you provided, I think there is something wrong with it.

 

Please consider modify your formula as below:

DropColumns(
    AddColumns(
        GroupBy(
            Filter(
                'Tasks LM',
                responsible.Email = User().Email
            ),
            "{Name}",
"employee", /* <-- Add formula here. Group your filtered result by {Name} column and "employee" column */ "GroupData" ), "Title", First(GroupData).Title, "endprobationperiod", First(GroupData).endprobationperiod, "responsible", First(GroupData).responsible ), "GroupData" )

 

If you just want to group your Filtered result by the employee, please modify your formula as below:

DropColumns(
    AddColumns(
        GroupBy(
            Filter(
                'Tasks LM',
                responsible.Email = User().Email
            ),
            "employee",      /* <-- Use "employee" as Group by column rather than "{Name}" column */
            "GroupData"
        ),
        "Title",
        First(GroupData).Title,
        "endprobationperiod",
        First(GroupData).endprobationperiod,
        "responsible",
        First(GroupData).responsible
    ),
    "GroupData"
)

Please take a try with above solution, check if the issue is solved.

 

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.
isabasu
Level: Powered On

Re: Filter by email and only return first result

@v-xida-msft thanks again for your answer!

 

I am not able to write "employee" for the column name of the GroupBy function. It's not selectable. What I have though is "OData__IsRecord". However, when I choose "OData__IsRecord" it will return only 1 result.

My code looks like below:

 

DropColumns(
    AddColumns(
        GroupBy(
            Filter(
                'Tasks LM',
                responsible.Email = User().Email
            ),
            "OData__IsRecord",
            "GroupData"
        ),
        "employee",
        First(GroupData).employee,
        "Title",
        First(GroupData).Title,
        "endprobationperiod",
        First(GroupData).endprobationperiod,
        "responsible",
        First(GroupData).responsible
    ),
    "GroupData"
)
Community Support Team
Community Support Team

Re: Filter by email and only return first result

Hi @isabasu ,

If the "employee" is a Person type column (Complex type column) in your SP list, you could not use it as group by column in your GroupBy formula.

 

Based on the issue that you mentioned, I think the AddColumns function could achieve your needs. Please consider modify your formula as below:

DropColumns(
    AddColumns(
        GroupBy(
            AddColumns(
Filter( 'Tasks LM', responsible.Email = User().Email ),
"EmployeeName", /* <-- Add a new column to your Filtered list based on the employee column, then use the new added column ("EmployeeName") as Group by column */
employee.DisplayName
), "EmployeeName", "GroupData" ), "employee", First(GroupData).employee, "Title", First(GroupData).Title, "endprobationperiod", First(GroupData).endprobationperiod, "responsible", First(GroupData).responsible ), "GroupData" )

Please take a try with above solution, then check if the issue is solved. Within your Gallery, you could use the following formula to get the display name of the employee directly:

ThisItem.EmployeeName

 

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.

Helpful resources

Announcements
firstImage

PowerApps Monthly Community Call!

Join us next Wednesday for our Demo Extravaganza, October 16, 2019 8am PDT.

Top Community Contributors for September  2019

Top Community Contributors for September 2019 🎉🎉

Let's thank our top community contributors

firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

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

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 271 members 4,239 guests
Please welcome our newest community members: