In Tableau, the MID function is used to extract a substring from a given string based on the specified starting position and length. It allows you to retrieve a portion of text from a string, starting from a particular position and extending for a specified number of characters.
The syntax for the MID function in Tableau is as follows:
MID(string, start, length)
- string is the source string from which you want to extract the substring.
- start is the position at which the extraction should begin. The first character of the string is at position 1.
- length is the number of characters to extract from the starting position.
Here's an example to illustrate the usage of the MID function in Tableau:
Let's say we have a dataset with a column called "Product Code," which contains alphanumeric codes of varying lengths. We want to extract a specific portion of the code based on the starting position and length.
Product Code
AB12345678
CD98765432
EF54321678
GH24681357
To extract the 4-character substring starting from the 3rd position in the "Product Code" column, we can use the MID function as follows:
MID([Product Code], 3, 4)
The result will be a new column with the extracted substrings:
Product Code Extracted Code
AB12345678 1234
CD98765432 9876
EF54321678 5432
GH24681357 2468
In this example, the MID function extracts a 4-character substring from the "Product Code" column, starting from the 3rd position. As a result, we obtain a new column called "Extracted Code" that contains the extracted substrings.
Note that the MID function is case-sensitive, and if the specified starting position is beyond the length of the string, or the length exceeds the available characters from the starting position, the function will return an empty string.
No comments:
Post a Comment
If you have any doubts. Please let me know