Where the Statistic shown on a table or a chart is naturally a percentage (i.e. %, Column %, Row %) or you are using a Pasted or basic R table, you can use the in the Appearance > Appearance > Number Format menu to display or hide the percent sign. However, if your Statistic is using numeric data (i.e. Average or Sum) that button is not available. For example, when computing Net Promoter Score (NPS), the calculation shows the Average of the values, but this is interpretable as a percentage. In these cases, you must use a Rule to add the % symbol to the values.
This post contains the steps to go from a table showing the Average...
to a table with the same statistics renamed (to Net Promoter Score) and with percent signs added:
Method
In this Method, you will create a custom rule for your table that transcribes the Average values to a Statistic that naturally shows a % (such as % Share). This statistic will also be renamed to whatever you'd like, such as "Net Promoter Score".
- Select the table.
- Go to Data > Statistics > Cells > select % Share.
- Go to Data > Rules > + > New Custom Rule (write your own JavaScript).
- Select Edit JavaScript.
- Input the below code:
//Hijack the % Share statistic to show the Average with %
The above code inserts the Average data into % Share. This code also renames the statistic as Net Promoter Score. You can amend the code to use a different statistic and label.
//Change if you want to show the "real" % Column Share in the table
//change that to a different % statistic you're not using
var pctstat="% Share";
//Change the text in "" below to the name you want for your statistic
var newname="Net Promoter Score";
//create variables for number of rows/columns for loop
var n_rows = table.numberRows; var n_columns = table.numberColumns;
//get the Average values shown in the table
var averages = table.get("Average");
//get the current percentage values to overwrite
var percents = table.get(pctstat);
//loop through the cells in each row/column
for (var r = 0; r < n_rows; r++) for (var c = 0; c < n_columns; c++)
//overwrite the percent value with the average value
percents[r][c] = averages[r][c];
//write the new values to the table
table.set(pctstat, percents);
//rename the percent statistic with what you want the new one called
form.setTranslation(pctstat,newname); - Click Play.
- Select OK.
- Go to Data > Statistics > Cells > deselect Average (the original statistic).
- If the symbols do not show, you can now add them via the object inspector > Appearance > Appearance > % button.