Calculate value based on existence of records matching given criteria - FileMaker Pro 13

StackOverflow https://stackoverflow.com/questions/22477030

  •  16-06-2023
  •  | 
  •  

Question

How can I write a calculation field in a table that outputs '1' if there are other (related) records in the same table that meet a given set of criteria and '0' otherwise?

Here's my problem explained in more detail:

I have a table containing 'students' and another containing 'exam results'. The 'exam results' table looks like this:

StudentID  SubjectID Level   Result
3234       1         2       A-
3234       2         4       B+
4739       1         4       C+

A student can only pass a Level 4 exam in subject 2 if they have also passed a Level 2 exam in subject 1 with a B+ or higher. I want to define a field in the 'students' table that contains a '1' if there exists an exam result belonging to the right student that meets these criteria and a '0' otherwise.

What would be the best way to do this?

Was it helpful?

Solution

Let us take an example of a Results table where the results are also calculated as a numeric value, e.g.

StudentID  SubjectID Level   Result   cResultNum
3234       1         2       A-       95
3234       2         4       B+       85
4739       1         4       C+       75

and an Exams table with the following fields (among others):

  • RequiredSubjectID
  • RequiredLevel
  • RequiredResultNum

Given these, you can construct a relationship between Exams and (another occurrence of) Results as:

Exams::RequiredSubjectID = Results 2::SubjectID
AND  
Exams::RequiredLevel = Results 2::Level
AND
Exams::RequiredResultNum ≤ Results 2::cResultNum

This allows each exam record to calculate a list of students that are eligible to take that exam as =

List ( Results 2::StudentID )

I want to define a field in the 'students' table that contains a '1' if there exists an exam result belonging to the right student that meets these criteria and a '0' otherwise.

This request is unclear, because there are many exams a student may want to take, and a field in the Students table can calculate only one result.

OTHER TIPS

You need to do a self-join in the table for the field you want to check, for example:

Exam::Level = Exam2::Level
Exam::Student = Exam2::Student

And for the "was passed" criteria I think you could do an "If" on the calculation like this:

If ( Last(Exam2::Result) = "D" and ...(all the  pass values) ; 1 ; 0 )

Edit: It could be just with the not pass value hehe I miss that it will be like this:

If ( Last(Exam2::Result) = "F" ; 0 ; 1 )

I hope this helps you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top