web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Filter on Many-to-many...
Power Apps
Unanswered

Filter on Many-to-many criteria

(2) ShareShare
ReportReport
Posted on by 894

So, I have a business requirement that only users who are related to a course should be able to view the course in our Course tool in Powerapps. 

 

The best way would be to be able to filter the gallery as follows: 

Filter('Course schedule', xxx_Courseschedule_SystemUser_SystemUser.'Primary email' = User().Email)

This gives errors that I am comparing a table with text.

 

Filter('Course schedule',Lower(User().Email) in Lower(xxx_Courseschedule_SystemUser_SystemUser.'Primary email'))

This gives a delegation warning and I don't get any results, although it's below max amount of records. 

 

Same with using the distinct:

Filter('Course schedule',Lower(User().Email) in Lower(Distinct(xx_Courseschedule_SystemUser_SystemUser,'Primary email')))


Due to that many people can be logged to one course and that many people are logged to several courses, it's a many-to-many relationship. Using Dataverse and Office365Users. Is this a lost cause?

 

Could a collection help?

Categories:
I have the same question (0)
  • fuzzy_fuzz Profile Picture
    229 on at

    Can you tell more about what xxx_Courseschedule_SystemUser_SystemUser is?

     

  • Gyllentid Profile Picture
    894 on at

    Hey @fuzzy_fuzz yes it's the relationship name between the datasources. You will find it in the relationship tab on the entity.

  • Gyllentid Profile Picture
    894 on at

    @fuzzy_fuzz Do you think it should be something else?

  • fuzzy_fuzz Profile Picture
    229 on at

    Is this xxx_Courseschedule_SystemUser_SystemUser  stored in a Sharepoint list?

    I would suggest to make a collection with xxx_Courseschedule_SystemUser_SystemUser.'Primary email' to see what is inside, so u can access to the data that matters to you.

    ClearCollect(whateverCol, xxx_Courseschedule_SystemUser_SystemUser.'Primary email')

     Run this code with a button and see what's inside File->Collections->whateverCol

  • Gyllentid Profile Picture
    894 on at

    hi @fuzzy_fuzz it's in a Dataverse, not Sharepoint. Basically, when two tables are joined with many-to-many relationships a hidden joint table is created between them, hence they don't work like look-ups.

     

    Unfortunately collections don't seem to work on the relationship-name alone. It was a good thought! 🙂

  • Gyllentid Profile Picture
    894 on at

    Does anyone have any idea how to solve the business requirement?

     

    Basically we have a need for many-to-many relationship between users and courses AND the requirement that only the courses you have should be visible. I tried looking into security roles and none could be specified from a relation of records, and neither have I found a way to filter it on User().Email.

    Please advice!

  • Verified answer
    Gyllentid Profile Picture
    894 on at

    So, I have found a solution for this. Hoping it will hold up...

     

    For other people who might be looking into ways into filtering data on a Many-to-many relationship between two tables I have collected the steps by steps.

     

    The way that I did this is by first creating a gallery with SystemUsers. I filter this on the current users email:

    Filter(SystemUser, Lower(Text('Primary email')) = Lower(User().Email))

    Skärmavbild 2022-02-03 kl. 16.01.16.png

    I added a check-box control so that the user has to click on their record.

     

    By clicking the gallery item we ensure that in a hidden gallery control all related records are listen:

    GalleryUsers.Selected.'Course schedule (key_Courseschedule_SystemUser_SystemUser)'

    Here we reference the relationship name between the two related tables.

    Skärmavbild 2022-02-03 kl. 16.01.52.png

     

    In a button control that is made visible when the checkbox is ticked add a ClearCollect with AllItems in the hidden gallery.

    Skärmavbild 2022-02-03 kl. 16.02.21.png

     

    In the gallery where you want to filter on related items we now can filter on the collection:

    Filter('Course schedule', 'Course schedule' in ColCourses.'Course schedule')

    Skärmavbild 2022-02-03 kl. 16.03.59.png

    Hoping this can help someone else working with many-to-many relationships where teachers can have many studentsand the students can have many teachers. This is geared for filtering on the current user.

     

  • Community Power Platform Member Profile Picture
    on at

    This is amazing, I've been banging my head for weeks and you sir have resolved the same business requirement I have! Thanks a bunch 😄 Although, I have a delegation warning because of "in" collection, but that okay, a solution is better than no solution!

     

    You're a hero!

  • Community Power Platform Member Profile Picture
    on at

    resolved delegation warning by using a flexible vertical gallery and setting Visible conditions on the item components themselves

  • Gyllentid Profile Picture
    894 on at

    Yeah, there are many ways to work around the delegations. I have had to find them too. But sometimes it's not idea.

    As per the annoyance with many to many, I have since created an in-between table in Dataverse to achieve the many to many. It became a little more seamless in app, but a little more tedious for the one working in model driven app. It's a give and take, innit.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard