Monday, June 19, 2023

Explain the String Function ' CHAR ' in Tableau with Example?

 In Tableau, the CHAR function is used to return the character represented by the specified ASCII code. It is the opposite of the ASCII function. The CHAR function can be used to convert ASCII code values into their corresponding characters.


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

CHAR(ascii_code)

Here, ascii_code is the ASCII code value for which you want to retrieve the corresponding character.


Example:


Let's say we have a dataset that contains a field called "ASCII Code," and we want to convert the ASCII code values into their corresponding characters. We can use the CHAR function in Tableau to achieve this. Assuming we have the following data:


ASCII Code

65

66

67

68


To convert the ASCII code values into characters, we can create a calculated field in Tableau. Here's an example:


  • Right-click on the data source in the Data pane and select "Create Calculated Field."
  • In the calculation editor, enter a name for the calculated field, for example, "Character."
  • Use the CHAR function to convert the "ASCII Code" field into its corresponding character:

          CHAR([ASCII Code])

In this calculation, [ASCII Code] refers to the field that contains the ASCII code values. The CHAR function converts each code value into its corresponding character.


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 display the characters based on the ASCII code values.


For example, if the "ASCII Code" field contains values 65, 66, 67, 68, the "Character" field will display the corresponding characters: A, B, C, D.


Note that the CHAR function only converts a single ASCII code value into a character. If you want to convert multiple ASCII code values into a string of characters, you would need to combine the CHAR function with other functions or techniques in Tableau.


Remember to consider the data type of the field you are applying the CHAR function to. The function returns a character, so if you are working with a numeric field, you may need to convert it to an ASCII code value before using the CHAR 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 ...