# Test if attribute value is within an array of values

 0 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 asked 17 May, 11:42 Andras 138●8●8●16 accept rate: 0%

 1 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 answered 07 Jun, 10:41 OF Collect ♦♦ 1.9k●5 accept rate: 19% 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? (26 Jun, 10:26) 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. (26 Jun, 14:28) OF Collect ♦♦
 toggle preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported

Question tags:

×270