---
schema_version: "1"
id: 0b8e6434c46e99eba69813dfd70edb0a65b985b7057702e7f140349dc7bf90fb
title: Data Manipulation Functions
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/analytics/bi_dev_guide_bindings/guides/bi-dashboard-bindings-functions-wave-designer-data-manipulation.md
canonical_url: https://developer.salesforce.com/docs/analytics/bi-dev-guide-bindings/guide/bi-dashboard-bindings-functions-wave-designer-data-manipulation.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 67ffedc27f8576bfdbcb17bf941c343305315ba399a53808b6948ee6cf8eeaf1
products:
  - Analytics Interactions
  - analytics
---
<!-- Contains overview of manipulation functions, coalesce Function, concat Function, flatten Function, join Function, slice Function, toArray Function, and valueAt Function -->
# Data Manipulation Functions

A data manipulation function changes the data into the format required by the data serialization function (see the next section). You can apply a manipulation function on the results from a data selection or other data manipulation function. If the input data is `null`, the manipulation function returns `null`, unless otherwise specified.

**note:** If data manipulation isn’t required, add a data serialization function to the results of the data selection functions.

## coalesce Function

Returns the first non-null source from a list of sources. Useful for providing a default value in case a function returns a null value.

### Syntax

```javascript
coalesce(source1, source2,...)
```

### Arguments

| Argument | Description |
| -------- | ----------- |
| source   | (Required) Source can be the results of a data selection or other data manipulation function. The source can have any shape. |

### Example
Function:
```javascript
coalesce(cell(step1.selection, 0, "column1"), "green")
```

Output:
The output is the result returned by `cell(step1.selection, 0, "column1")`. However, if `cell(step1.selection, 0, "column1")` returns `null`, then the output is

```nolang
"green"
```

See Also
- [Change the Map Type Based on a Toggle Widget](https://developer.salesforce.com/docs/analytics/bi-dev-guide-bindings/guide/bi-dashboard-bindings-wave-designer-changing-map-type.md)

## concat Function

Joins streams from multiple sources into a one- or two-dimensional array. Null sources are skipped.

### Syntax

```javascript
concat(source1, source2,...)
```

### Arguments

| Argument | Description |
| -------- | ----------- |
| source   | (Required) Each source can be the results of a data selection or other data manipulation function. Each source must be either a one- or two-dimensional array. An error occurs if you try to concatenate data from sources of different shapes. For example, the following function produces an error: `concat(["a", "b"], ["c", "d", "e"])`. |

### Examples
Function:
```javascript
concat(["a", "b"], ["c", "d"])
```

Output:

```sql
["a", "b", "c", "d"]
```
---
Function:

```javascript
concat([["a", "b"]], [["c", "d"]])
```

Output:

```sql
[["a", "b"], ["c", "d"]]
```

## flatten Function

Flattens a two-dimensional array into a one-dimensional array.

### Syntax

```javascript
flatten(source)
```

### Arguments

| Argument | Description |
| -------- | ----------- |
| source   | (Required) Source can be the results of a data selection or other data manipulation function. The source must be a two-dimensional array. Otherwise, an error occurs because there’s no reason to flatten a one-dimensional array or scalar. |

### Example
Function:
```javascript
flatten([["CDG", "SAN"], ["BLR", "HND"], ["SMF", "JFK"]])
```

Output:

```sql
["CDG", "SAN", "BLR", "HND", "SMF", "JFK"]
```

## join Function

Converts a one- or two-dimensional array into a string by joining the elements using the specified token. An error occurs if the data has any other shape.

### Syntax

```javascript
join(source, token)
```

### Arguments

| Argument | Description |
| -------- | ----------- |
| source   | (Required) Source can be the results of a data selection or other data manipulation function. The source must be a two-dimensional array. Otherwise, an error occurs. |
| token    | (Required) Any string value, like `+` or `,`. |

### Examples
Function:
```javascript
join(["a", "b", "c"], "+")
```

Output:

```sql
["a+b+c"]
```
---
Function:

```javascript
join([["a", "b", "c"], [1, 2]], "~")
```

Output:

```sql
["a~b~c~1~2"]
```
## slice Function

Selects one or more values from a one-dimensional array given a start and, optionally, an end position, and returns a one-dimensional array. An error occurs if the start value is greater than the end value. Negative indices are supported.

### Syntax

```javascript
slice(source, start, end)
```

### Arguments

| Argument | Description |
| -------- | ----------- |
| source   | (Required) Source can be the results of a data selection or other data manipulation function. The source can have any shape. |
| start    | (Required) Index that identifies the start value in the array. For example, `0` represents the first element in the array. |
| end      | (Optional) Index that identifies the end value in the array. |

### Example

```javascript
slice(step.selection, -1, 0)
```

Returns the last selected row.

## toArray Function

Converts scalars to a one-dimensional array, and one-dimensional arrays to a two-dimensional array. For example, use this function to convert the scalar result of a cell function to an array, which is required by compact-form measures, groups, and order clauses. The function returns an error if the input is a series of static one-dimensional arrays, a two-dimensional array, or a mix of scalars and one-dimensional arrays.

### Syntax

```javascript
toArray (source1, source2,...)
```

### Arguments

| Argument | Description |
| -------- | ----------- |
| source   | (Required) The input must be scalars, including static values, or one-dimensional arrays. |

### Examples

Consider these Opportunities query result.

| Oppty_Name | Owner | Region   | Amount | Created_Date |
| ---------- | ----- | -------- | ------ | ------------ |
| Alpha      | Danny | Americas | 1000   | 2/20/2017    |
| Bravo      | Danny | Americas | 500    | 4/15/2017    |
| Charlie    | Jeff  | EMEA     | 2000   | 5/1/2017     |

These interactions use the Opportunities query as a source.

| Interaction | Result |
| ----------- | ------ |
| `toArray( cell(Opportunities.selection, 0, "Region") )` | `["Americas"]` |
| `toArray( "EMEA" )` | `["EMEA"]` |
| `toArray( cell(Opportunities.selection, 0, "Region"), "EMEA" )` | `["Americas", "EMEA"]` |
| `toArray( column(Opportunities.selection, ["Oppty_Name"]), column(Opportunities.selection, ["Region] )` | `[["Alpha", "Bravo", "Charlie"], ["Americas", "Americas", "EMEA"]]` |
| `toArray( column(Opportunities.selection, ["Oppty_Name", "Region"]) )` | Error. The column interaction function returns a two-dimensional array, which is an invalid input. |
| `toArray( [1, 2, 3], [4, 5, 6] )` | Error. The input can't be a series of static one-dimensional arrays. |

## valueAt Function

Returns the single scalar value at the given index.

### Syntax

```javascript
valueAt(source, index)
```

### Arguments

| Argument | Description |
| -------- | ----------- |
| source   | (Required) Source can be the results of a data selection or other data manipulation function. The source can have any shape. |
| index    | (Required) Negative indexes are supported. If you specify an index that doesn't exist, the function returns null. |

### Example

```javascript
valueAt(cell(step.selection, 0, "column"), -1)
```

Returns the last selected value.
