CHAR(10) - The Secret to Creating Line Breaks in Tableau Calculations

I’ve pulled a set of data for the top pitchers in Major League Baseball in 2017. Let’s say we want to do an analysis to see which of the best pitchers got extra help from their teams and which didn’t.

I’ll start by creating a scatter plot displaying wins and losses by each pitcher. Pitchers with dark blue circles that are farther toward the top did not get much run support from their teams. Pitchers with lighter circles that are closer to the bottom did.

27-1.png

Now let’s say we want to add a label to each point displaying the player’s name and win-loss record. We would create a calculated field like this:

27-2.png

And then drop it on the Label tab in the Marks Card:

27-3.png

Notice how messy the labels are after doing this. You might think, “Maybe we can clean this up by splitting the name and record to two different lines.” Unfortunately, creating a line break in the calculated field actually doesn’t affect the label display.

27-4.png

This is where the function CHAR() comes in. What CHAR() does is takes a number and converts it into an ASCII character. The character 10 represents a new line feed. Watch what happens when we add this to the calculation.

27-5.png

Result:

27-6.png

The labels look much cleaner after editing the calculation and doing a small amount of manual rearranging.

27-7.png

 

Need more help?  Please contact us at freesupport@onenumber.biz.

 

How to Kill Rats with Data (Tableau REGEXP_MATCH)

Data Blending in Tableau - How it Works and When You Need it

0