> 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).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://concentra-analytics.gitbook.io/working-with-data/strings/slice.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
