> For the complete documentation index, see [llms.txt](https://concentra-analytics.gitbook.io/working-with-data/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://concentra-analytics.gitbook.io/working-with-data/strings/slice.md).

# Slice

Slice functions let you extract a specified substring from a text value. This is a quick way of removing unwanted flags at the ends of a text value or mapping strings to shorter values.

## Excel

* \=\~LEFT!\~(‹string›«, length») <br>
* \=\~RIGHT!\~(‹string›«, length»)

```
=LEFT(A1) // "Female" -> "F"
```

```
=RIGHT(A2,5) // "MAIN24601" -> "24601"
```

NB. If «length» is left blank, it returns the 1st digit only.

## Tableau

* \~LEFT!\~(‹string›, ‹length›) <br>
* \~RIGHT!\~(‹string›, ‹length›)

```
LEFT([Gender], 1) // "Female" -> "F"
```

```
RIGHT([Cost Code], 5) // "MAIN24601" -> "24601"
```

## Alteryx

* \~LEFT!\~(‹string›, ‹length›) <br>
* \~RIGHT!\~(‹string›, ‹length›)

```
LEFT([Gender], 1) // "Female" -> "F"
```

```
RIGHT([Cost Code], 5) // "MAIN24601" -> "24601"
```

## OrgVue

The general format of splice in OrgVue is: ‹dimension›.value.\~slice!\~(‹start\_index›«, end\_index») <br>

* **Left:** ‹dimension›.value.\~slice!\~(0, ‹end\_index›) <br>
* **Right:** ‹dimension›.value.\~slice!\~(-‹start\_index›)

```
node.gender.value.slice(0,1) // "Female" -> "F"
```

```
node.costcode.value.slice(-5) // "MAIN24601" -> "24601"
```

NB.:

* The first character in a string has the index `0`.&#x20;
* Negative numbers count from the end of the string.&#x20;
* If only 1 index is supplied, the default is to return all subsequent characters after that index, e.g.

  ```
  node.ordernumber.value.slice(3) // "NCF1066" -> "1066"
  ```

## tSQL

* \~LEFT!\~(‹field›, ‹length›) <br>
* \~RIGHT!\~(‹field›, ‹length›) <br>
* \~MID!\~(‹field›, ‹start›«, length»)

```
SELECT LEFT(Gender, 1) AS GenderCode
FROM EmployeesData
-- "Female" -> "F"
```

```
SELECT RIGHT(CostCode, 5) AS CC 
FROM ProductsData
-- "MAIN24601" -> "24601"
```

```
SELECT MID(OrderNumber, 2, 4) AS OrderYear
FROM OrdersData
-- "UK2008ABP" -> "2008"
```

## Python

The general splice format in Python is: ‹string›\[«start\_index»:«end\_index»] <br>

* **Left:** ‹string›\[:«end\_index»] <br>
* **Right:** ‹string›\[-«start\_index»:]

```
gender[:1] # "Female" -> "F"
```

```
costCode[-5:] # "MAIN24601" -> "24601"
```

NB.:

* The first character in a string has the index `0`.&#x20;
* Negative numbers count from the end of the string.&#x20;
* If only the «start\_index» is supplied and no `:` is included, the expression behaves like `[:1]` has been provided, e.g.:

```
orderNumber[3] # "NCF1066" -> "1"
```

* The above examples assume variables have been declared for  `gender`, `costCode`, and `orderNumber`. For more information, go to [General > Variables](https://orgvue.gitbooks.io/formula-translator/content/general/variables.html).
