> For the complete documentation index, see [llms.txt](https://help.pickzen.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.pickzen.com/guides/nocode/functions/refine.md).

# REFINE

### Details

Rules are evaluated in groups, so resulting items after evaluating a group are used as input to evaluate the next group.

### Syntax

**REFINE(items, table, \[rowsSelector, colsSelector, out])**

| Argument name                                       | Description                                  |
| --------------------------------------------------- | -------------------------------------------- |
| <p><strong>items</strong></p><p>Required</p>        | Item list to refine.                         |
| <p><strong>table</strong></p><p>Required</p>        | Table with the refining rules.               |
| <p><strong>rowsSelector</strong></p><p>Optional</p> | Selector of rows. All rows by default.       |
| <p><strong>colsSelector</strong></p><p>Optional</p> | Selector of columns. All columns by default. |
| <p><strong>out</strong></p><p>Optional</p>          | Also includes the results in a list.         |

**Table syntax**

| **Column name**                                         | Description                                                                                                                                                                                                                                                                                                                                                                                                  |
| ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><strong>answer</strong></p><p>Required, Multiple</p> | Rule to evaluate. It can be a formula.                                                                                                                                                                                                                                                                                                                                                                       |
| <p><strong>group</strong></p><p>Optional</p>            | Group to which the answer belongs. If not specified, all rules will belong to the default group.                                                                                                                                                                                                                                                                                                             |
| <p><strong>mode</strong></p><p>Optional</p>             | <p><strong>retain</strong> Filter the current list retaining only the matching items.</p><p><strong>sretain</strong> (default) Filter the current list retaining only the matching items that appear in any other matching <em>sretain</em> rules of its group.</p><p><strong>order</strong>  Do not filter items, only assigns a weight to the items.</p><p><strong>exclude</strong> Exclude the items.</p> |
| <p><strong>weight</strong></p><p>Optional</p>           | Assigns points to items that will be used to order them. All items have a weight of 1 by default.                                                                                                                                                                                                                                                                                                            |
| <p><strong>\<other columns></strong></p><p>Required</p> | Any other column is treated as items holder.                                                                                                                                                                                                                                                                                                                                                                 |

### Examples

#### Example 1

Say we have a list of these three items \[red, blue,redblue]. They could be for example shirts: one red, another blue and, another red and blue.

![rules1](/files/-MA5zpv6jA_MheKuPSL3)

**REFINE(items, rules1)**

* If *likes\_red* and *likes\_blue* are *true*, returns \[*red, blue, redblue*]
* If *likes\_red* is *true*, returns \[*red, redblue*]

![rules2](/files/-MA6-In1ie-gIhRQbxMx)

**REFINE(items, rules2)**

* If *likes\_red* and *likes\_blue* are true, returns only \[*redblue*] because it is the only matching item that appears in all matching sretain rules of its group (the default group in this case).
* If *likes\_red* is true, returns \[*red, redblue*]

![rules3](/files/-MA60158c-r3P6rI4J_l)

**REFINE(items, rules3)**

* If *likes\_red* and *likes\_blue* are *true*, returns \[*redblue, red, blue*]. Note that *redblue* is returned first because it appears in both rules so its weight is higher.
* If *likes\_red* is true, returns \[*red, redblue*]

![rules4](/files/-MA61WlF3urBh_jvpnZX)

**REFINE(items, rules4)**

* If *likes\_red* and *hates\_blue* are *true*, returns only \[red] because *redblue* will be excluded.

#### Example 2

List *items* = \[*p1, p2, p3, p4, p5, p6, p7, p8*]

![rules](/files/-MA63t1EoDx6mjTpFNll)

**REFINE(items, rules)**

* If *a1* and *a3* are *true*, returns \[*p1, p2*]
* If *a1* and *a4* are *true*, returns \[*p3, p4*]
* If *a1* and *a2* are *true*, returns \[*p1, p2, p3, p4, p5, p6, p7, p8*]
* If *a1*, *a2*, and a3 are *true*, returns \[*p1, p2, p7, p8*]

#### Example 3

List *items* = \[*p1, p2, p3, p4, p5, p6, p7, p8*]

![rules](/files/-MA67KqAuIruN4lEJbvn)

**REFINE(items, rules)**

* If *a1*, *a3* and *a5* are *true*, returns \[*p5, p6, p7, p8*]

<br>

\ <br>
