Sunday, June 18, 2023

Explain the String Function ' ASCII ' in tableau with Example?

 In Tableau, the ASCII function is used to return the ASCII code value of the first character in a given string. The ASCII code represents the numerical value assigned to each character in the ASCII character set. The function can be useful for various tasks, such as text manipulation, character analysis, or sorting based on ASCII values.

The syntax for the ASCII function in Tableau is as follows:


Here, 'string_expression' is the string or field containing the text for which you want to determine the ASCII code value.


Let's say we have a dataset that contains a field called "Product Name," and we want to extract the ASCII code value of the first character for each product. We can use the ASCII function in Tableau to achieve this. Assuming we have the following data:

Product Name





To calculate the ASCII code value for the first character of each product name, we can create a calculated field in Tableau. Here's an example:

1.Right-click on the data source in the Data pane and select "Create Calculated Field."

2.In the calculation editor, enter a name for the calculated field, for example, "First Character ASCII."

3.Use the ASCII function to extract the ASCII code value of the first character from the "Product     Name" field:

    ASCII(LEFT([Product Name], 1))

4.In this calculation, LEFT([Product Name], 1) extracts the first character of the "Product Name"     field using the LEFT function. The ASCII function then returns the ASCII code value for that         character.

5.Click "OK" to create the calculated field.

After creating the calculated field, you can use it in your visualizations, such as tables, charts, or calculations, to analyze or manipulate the ASCII code values. For example, you can sort the products based on their ASCII values or use conditional logic to perform specific actions based on the ASCII values.

Note that the ASCII function only considers the first character in the string. If you want to calculate the ASCII code values for all characters in a string, you would need to use additional functions or techniques in Tableau.

Remember to consider the data type of the field you are applying the ASCII function to. The function operates on text strings, so if you are working with a numeric field, you may need to convert it to a string before using the ASCII function.

No comments:

Post a Comment

If you have any doubts. Please let me know

How can you create an alias for a table in a SQL query?

In SQL, you can create an alias for a table in a query to give the table a temporary, alternative name that you can use in the query. Table ...