---
title: "Test if attribute value is within an array of values"
url: "https://openforis.support/questions/1799/test-if-attribute-value-is-within-an-array-of-values"
tags: ["collect"]
status: "accepted"
score: 0
answer_count: 1
asked: "2018-05-17T11:42:33"
last_activity: "2018-06-26T14:28:52"
source: "Open Foris Support - Q&A Forum"
license: "Copyright Open Foris, 2026. Some rights reserved under creative commons license."
---

# Test if attribute value is within an array of values

Asked by Andras on 2018-05-17

Dear OF Team,

Is there a way to do the following test more nicely/shorter:
tree[species=1 or species=8 or species=10 or species=11 or species=12 or species=16 or species=19 or species=22 or species=23]

What I'm looking for is something like this (e.g. in R):
tree[species %in% c(1,8,10,11,12,16,19,22,23)]

Could this be implemented if doesn't exist yet?

Thanks!
Andras


## Accepted answer (score 1, by Stefano (OF) on 2018-06-07)

Link: https://openforis.support/questions/1799/test-if-attribute-value-is-within-an-array-of-values/1820

Hi András,  
In the latest version of Collect (3.22.x) there is a new function `idm:array` that you could use in combination with `idm:contains` function to simplify your expression, that will become:  

    idm:contains(idm:array(1,8,10,11,12,16,19,22,23), species)

  
Many thanks,  
Open Foris Team

> Hi, It seems there is a problem with the expression above. If I try to use it to get a subset of a group of items, it doesn't work: count(parent()/tree[idm:contains(idm:array(1,8,10,11,12,16,19,22,23),species)]) Am I doing something wrong? (Andras)
> The species code is an alphanumeric value, so it must be wrapped into single or double quotes. Try to use this expression instead: count(parent()/tree[idm:contains(idm:array('1','8','10','11','12','16','19','22','23'),species)]) However, I would split the expression into 2 separate calculated attributes, one attribute that says if a species in of a specific type and the other one that counts the trees of that species, and I would even move the count outside of the 'tree' entity, since it does not depend on the current tree item. (Stefano (OF))
