Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

Filter on Many-to-many criteria

(2) ShareShare
ReportReport
Posted on by 892

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:
  • Gyllentid Profile Picture
    892 on at
    Re: Filter on Many-to-many criteria

    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.

  • Community Power Platform Member Profile Picture
    on at
    Re: Filter on Many-to-many criteria

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

  • Community Power Platform Member Profile Picture
    on at
    Re: Filter on Many-to-many criteria

    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!

  • Verified answer
    Gyllentid Profile Picture
    892 on at
    Re: Filter on Many-to-many criteria

    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.

     

  • Gyllentid Profile Picture
    892 on at
    Re: Filter on Many-to-many criteria

    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!

  • Gyllentid Profile Picture
    892 on at
    Re: Filter on Many-to-many criteria

    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! 🙂

  • fuzzy_fuzz Profile Picture
    229 on at
    Re: Filter on Many-to-many criteria

    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
    892 on at
    Re: Filter on Many-to-many criteria

    @fuzzy_fuzz Do you think it should be something else?

  • Gyllentid Profile Picture
    892 on at
    Re: Filter on Many-to-many criteria

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

  • fuzzy_fuzz Profile Picture
    229 on at
    Re: Filter on Many-to-many criteria

    Can you tell more about what xxx_Courseschedule_SystemUser_SystemUser is?

     

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,700 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,015 Most Valuable Professional

Leaderboard