cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
TiredOldCoder
Helper I
Helper I

Filtering with lookup fields in PowerApps

I have three lists:

Student: ID, Title

Class: ID, Title

AssignedClass: ID, Title,  StudentName[lookup Student.Title],  ClassName[lookup Class.Title]

Task: create set of Class items that the Student is NOT assigned, for a specific student

I cannot for the life of me get this to work. Below is a sample of one attempt

Filter(Class, Not(Title in Filter(
        'AssignedClass',
        StudentName.Value = "Bob"
     ).ClassName)
)

Errors indicate String cannot be compared to a Record. Any thoughts?

1 ACCEPTED SOLUTION

Accepted Solutions
wyotim
Resident Rockstar
Resident Rockstar

So, unable to let this go Smiley Very Happy I made a simple mock-up of your data and a simple app to view it in. One way I accomplished what you are after is I made a dropdown to select students. In the OnChange section of the dropdown I put:

Clear(NotAssignedClass);
ForAll(
    Class,
    If(
        IsBlank(LookUp(AssignedClass, StudentName = Dropdown1.Selected.Title && ClassName = Class[@Title])),
        Collect(
            NotAssignedClass,
            {ID: Class[@ID], Title: Class[@Title]}
        )
    )
)

This creates a collection called NotAssignedClass which is a list of all classes the student selected in the dropdown is not in, according to the AssignedClass data.

 

Feel free to let me know if this helps or needs further adjustment/explaination.

View solution in original post

4 REPLIES 4
wyotim
Resident Rockstar
Resident Rockstar

Off the top of my head, I think the error is coming from this part:

StudentName.Value = "Bob"

StudentName.Value is a record whereas "Bob" is a string. Maybe try:

StudentName = "Bob"

If that doesn't do the trick, let me know and I'd be happy to help further.

wyotim
Resident Rockstar
Resident Rockstar

So, unable to let this go Smiley Very Happy I made a simple mock-up of your data and a simple app to view it in. One way I accomplished what you are after is I made a dropdown to select students. In the OnChange section of the dropdown I put:

Clear(NotAssignedClass);
ForAll(
    Class,
    If(
        IsBlank(LookUp(AssignedClass, StudentName = Dropdown1.Selected.Title && ClassName = Class[@Title])),
        Collect(
            NotAssignedClass,
            {ID: Class[@ID], Title: Class[@Title]}
        )
    )
)

This creates a collection called NotAssignedClass which is a list of all classes the student selected in the dropdown is not in, according to the AssignedClass data.

 

Feel free to let me know if this helps or needs further adjustment/explaination.

View solution in original post

I had to make a few tweaks, but yes - @wyotim YOU NAILED IT!

 

Clear(NotAssignedClass);
ForAll(
    Class,
    If(
        IsBlank(LookUp(AssignedClass, StudentName.Value = Dropdown1.Selected.Title && ClassName.Value = Class[@Title])),
        Collect(
            NotAssignedClass,
            {ID: Class[@ID], Title: Class[@Title]}
        )
    )
)

 

Thank you so much!

Happy to help out!

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

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Carousel April Dunnam Updated 768x460.jpg

Urdu Hindi D365 Bootcamp

Dont miss our very own April Dunnam’s The Developer Guide to the Galaxy! Find out what the Power Platform has to offer for the traditional developer.

Top Solution Authors
Top Kudoed Authors
Users online (2,464)