Setting Display Names for Expressions


The last couple tips have been more advanced uses of expressions, so I thought I would follow those with a basic, yet powerful example.  The first thing that came to mind was to explain how to rename an expression. Even though you can create powerful and complex expressions to alter how the data in your visualizations is displayed, there are also very simple expressions. In fact, expressions are used behind the scenes even when setting an axes value through the User Interface.

Suppose you want a Bar Chart that displays the Sum of 'Electronics' sold per 'Store Location'. You can set the X-axis to use the 'Store Location' column and the Y-axis to use the 'Electronics' column and select Sum as the aggregation method. 

 


 
When you do that, you actually have created a basic expression.   You can view the expression dialog (by right clicking on the axis and selecting 'Custom Expressions'') to see the expression created:

 


 
Let's say you do not want the axes to show Sum(Electronics). If you want to rename the output, you can use the 'Display name:' field , also in the expression dialog, to enter the display name,

 

 

This works great. However, let's say you want the Bar Chart to have multiple columns on the y-axis (or any access for that matter). For example, the Bar Chart below shows both the Sum of Electronics and the Sum of Furniture on the Y-axis.

 

 

The expression used internally for this is:

 


 

With this, we cannot use the display name field to rename the output as there are multiple columns used .  If you want to rename the output expression for each column, you must use the As keyword inside your expression.

The As keyword will be paired with an expression and allow you to specify an output that is displayed anywhere that expression should be displayed (in all the axis selectors, tooltips, labels, etc')

In this example, we can right click on any of the y-axis columns and select 'Custom Expressions'' and enter the following in the expression dialog:
 

 

You can see from the result below that anywhere the expression is used, in this case the Color By and y-Axis, the display names set from the As keyword are used.

 


 
When using the As keyword, if your desired display name is a single string without spaces, you can just enter it as is (i.e. As Electronics). However, if your display name is multiple strings, you need to enclose the name in brackets (i.e. As [Total Amount of Electronics Sold])

The As keyword as well as many other features are discussed in our SP 141 Computational Analytics class , which can be taken using one of our various delivery options: instructor-led onsite or public, blended training, or our bootcamp offering.