Skip to content

Commit

Permalink
Merge pull request #342 from gristlabs/reference-lookup-enrollment-2
Browse files Browse the repository at this point in the history
new-rl-enroll-changes
  • Loading branch information
MichaelNickolas authored May 13, 2024
2 parents eff0207 + b5c6538 commit 0362876
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions help/en/docs/references-lookups.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,33 @@ The entire formula would be `Sponsors.lookupOne(Contact_Email=$Registration_Emai

Now, we have the Sponsor Level listed in the All Registrations table for those attendees whose emails also appear on the sponsor list.

## lookupOne and sort_by ##

When the `lookupOne` function encounters multiple matching results, it returns the first one by row ID. The optional `sort_by` parameter can be used to sort these results by another field, to determine which one would be returned as the first match. You can also prefix the column ID with "-" to reverse the order.

For instance, consider this example from the [Class Enrollment](https://templates.getgrist.com/doc/afterschool-program) template. This template tracks enrollment for extracurricular and other classes - logging information for students, families, and staff.

On this page, we have a list of students and their respective information.

<span class="screenshot-large">*![student-table](images/references-lookups/students-final-2.png)*</span>

Additionally, we have a Families page that outlines the parent of each student and we’d like to find which student in each family is the oldest. So, we would create an oldest student column.

<span class="screenshot-large">*![family-table](images/references-lookups/families-final-2.png)*</span>


Then, the following formula would look at the Students table, find the specific students associated with each family, sort them by their birthday, and return the one student with the earliest birthday:

`Students.lookupOne(Family=$id, sort_by="Birthday")`

In this case, this would return: Raddon, Brockie.

Alternatively, if we want to find the youngest student, the formula would include "-":

`Students.lookupOne(Family=$id, sort_by="-Birthday”)`

In this case, this would return: Raddon, Care.

## Understanding record sets

Sometimes a record may reference multiple records in another table. Multiple references can be made with a Reference List Column.
Expand Down

0 comments on commit 0362876

Please sign in to comment.