Hi,
I am using SQL tables as the data source for my Power Apps. I am having trouble in finding a delegable function to filter for rows from one table based on the value from another table which has a many-to-many relationship with the current table I want to filter.
Suppose I have two tables: STUDENT and COURSE that have many-to-many relationship between them (one student can enroll to multiple courses and one course can have multiple students). I also have a table to handle the many-to-many relationship between the two tables called STUDENT_COURSE:

Let's say I want to filter for all students who attend a Course with a CourseId = 37, what I would normally do is:
// Find all studentId of all students who enroll to the course by filtering the STUDENT_COURSE table
Set(currentStudentIdsInCourse,
Filter(STUDENT_COURSE, CourseId = 37).StudentId
);
// Step 2: Filter for all Students from the STUDENT table using the studentIds obtained from the previous step and get their names
Set(studentNamesInCourse,
Filter(STUDENT, studentId in currentStudentIdsInCourse).StudentName
);
Or alternatively, I can also use CountRows:
// OR I can also use CountRows as the filtering condition to find students who enroll to the course
Set(studentNamesInCourse,
Filter(STUDENT, CountRows(
Filter(STUDENT_COURSE, courseId = 37 && STUDENT[@studentId] = STUDENT_COURSE[@studentId])
) > 0
).StudentName
);
// Alternatively, I can also use the "in" operator in a single step like shown below instead of what I did previously:
Set(studentNamesInCourse,
Filter(STUDENT, STUDENT[@studentId] in
Filter(STUDENT_COURSE, courseId = 37 && STUDENT[@studentId] = STUDENT_COURSE[@studentId]).studentId
).StudentName
);
Using either "in" or CountRows works fine. However, both of them throw out a Delegation warning and I found out that both "in" operator in this case and the CountRows function are non-delegable. Reading into this documentation from Microsoft, the "in" operator is supposed to be delegable as long as the operator is used for columns in the base data source which I believe I have done correctly (both "in" operator usage in my example uses the studentId column from the STUDENT table, studentId is a column inside the STUDENT table which acts as the base data source).
I am worried that in the future my database would grow to accommodate even more data which is why I am concerned with these Delegation problems.
Are there any other alternative functions or methods for this filtering process?
Thanks a lot!