# 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](https://1947171238-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LrTaL6FQB3RzlkCwQfN%2F-MA5uOd958nf5Wyve-gr%2F-MA5zpv6jA_MheKuPSL3%2Fimage.png?alt=media\&token=1a2aab1b-229b-4e30-9596-8e1de05b06a5)

**REFINE(items, rules1)**

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

![rules2](https://1947171238-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LrTaL6FQB3RzlkCwQfN%2F-MA5uOd958nf5Wyve-gr%2F-MA6-In1ie-gIhRQbxMx%2Fimage.png?alt=media\&token=1481d8fb-2c91-4d81-8838-fd5ef68e7dd8)

**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](https://1947171238-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LrTaL6FQB3RzlkCwQfN%2F-MA5uOd958nf5Wyve-gr%2F-MA60158c-r3P6rI4J_l%2Fimage.png?alt=media\&token=306f211e-13b9-4ad7-b421-1d7a7f85742e)

**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](https://1947171238-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LrTaL6FQB3RzlkCwQfN%2F-MA61A-or7wIXUXC3owj%2F-MA61WlF3urBh_jvpnZX%2Fimage.png?alt=media\&token=1daf02bd-91aa-4185-b423-28d44e15d3d2)

**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](https://1947171238-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LrTaL6FQB3RzlkCwQfN%2F-MA61A-or7wIXUXC3owj%2F-MA63t1EoDx6mjTpFNll%2Fimage.png?alt=media\&token=5cf01116-d423-4589-9d57-99de3066a470)

**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](https://1947171238-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LrTaL6FQB3RzlkCwQfN%2F-MA66vKqehLZaplsjyFQ%2F-MA67KqAuIruN4lEJbvn%2Fimage.png?alt=media\&token=17bde857-aa9c-4506-a3ff-8710d3e7904e)

**REFINE(items, rules)**

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

<br>

\ <br>
