---
title: "Lookup() to pull values"
url: "https://openforis.support/questions/3370/lookup-to-pull-values"
tags: ["collect"]
status: "answered"
score: 0
answer_count: 1
asked: "2022-04-07T14:57:27"
last_activity: "2022-10-24T14:30:49"
source: "Open Foris Support - Q&A Forum"
license: "Copyright Open Foris, 2026. Some rights reserved under creative commons license."
---

# Lookup() to pull values

Asked by janklein on 2022-04-07

Hello again,

In my survey, I sample multiple individuals belonging to the same taxon. Each taxon is collected once in the field. Now, I wish to automatically associate each subsequent observation with the corresponding reference specimen.

Technically speaking, I want to pull a value (specimen_name) based on another value (taxon_name). I reckon that using idm:lookup() is the right approach here but I fail to correctly implement the code. Lookup() requires a list of values. Is it that I need to create that list beforehand?

My relevant fields:
 - taxon_name
 - specimen_name
 - taxon_already_sampled (yes/no)
 - reference_specimen

Desired output:
Taxon1 is observed for the first time in the field (taxon_already_sampled = no) and is collected, hence a specimen name is attributed ("specimen1"). Subsequently, taxon1 is again encountered in the field (taxon_already_sampled = yes); in this case the individual will not be collected but instead the column reference_specimen should be auto-filled with "specimen1".

Thanks in advance for the help.

Best,
Jan


## Answer (score 1, by Stefano (OF) on 2022-05-06)

Link: https://openforis.support/questions/3370/lookup-to-pull-values/3392

Dear Jan,  
The lookup function (idm:lookup) is something you should use to fetch data from a table of the database, is not what you need in your case.  
What you should do to get the value of an attribute in another row of the same table is an expression like this:  

`parent()/tree[taxon_name = $context/taxon_name and idm:position() != idm:position($context)] / specimen_name`  

With this expression you will get the value of `specimen_name` of another having the same `taxon_name` as the current row (but different position in the table, of course).  

Let us know, many thanks.  
Open Foris Team

> The function does exactly what I wanted to do. Thank you very much! (janklein)
