top of page

KPI Series: Automatic Highlight Background and Text Swap

In last week's blog Use KPI as a Filter! I reviewed several dashboards that allowed you to click on them to filter the rest of the dashboard!


This method is 3 sheets, 2 sheets to the wind.


This week I want to discuss how to create Zak Geis's header with the dark background to indicate that the metric is selected. It also changes from black text to white text!


The dashboard I am referring to is here.


Steps to create this.


First you will need to create a parameter for the metrics you would like. I created a simple string parameter listing the values I will have in my dashboard.


I named this p_MetricSwap. This is a practice some developers use to put a lowercase "p" followed by an underscore.



They then name the calculated field the same name without the "p_".

In my calculated field below I am only pulling the values for the current month and the current year. You can get these from looking at the calculations in this past blog post.



Then you need to create the KPI sheet.

I put Sales on a worksheet and format it as an Attribute.

Then I do the same thing for Profit.

This creates two placeholder columns.



Then for document purposes I create the two below calculated fields;


CustomersPlaceholder

Min(0)


OrdersPlaceholder

Min(0)


These both go on the Columns shelf next to the ATTR(Sales) and ATTR(Profit) pills.

I then changed the Mark type to Text on the All Marks card.

I also expanded the placeholders to the Entire View.



So now I needed to put measures in each of these cards.


For the ATTR(Sales) card


MetricSales

IF [p_MetricSwap]="Sales" then SUM([Sales (This Month Curr Year)])

END


MetricSalesNotSelected

IF [p_MetricSwap]<>"Sales" then SUM([Sales (This Month Curr Year)])

END


MetricSalesLabel

IF [p_MetricSwap]="Sales" then "SALES"

END


MetricSalesNotSelectedLabel

IF [p_MetricSwap]<>"Sales" then "SALES"

END


These calculations may appear to be duplicated, but they are not. The Label Marks card will appear as below



I highlighted the calculation "Metric Sales" that will be shown when the Sales value is selected in the parameter in white text. I also change the color of the font for the "MetricSalesLabel" calculation as white.


When the Sales parameter is not selected, the other two calculations will appear in black text for this placeholder card.


I then replicated these calculations for the other three placeholders.

The worksheet will also need to have the default shading removed.


MetricProfilLabel calculation


Profit Marks card label


When they are all done, the worksheet should appear as below;

I renamed this sheet as KPIText.

Now for the background sheet. I created an Excel document with the column name of Value and all of the parameters listed in each row, spelled exactly how they appear in Tableau. So if you use title case format, use title case in the cells, etc. I also named this data source AllMetricsList.



I brought this Excel sheet in as a secondary data source.

I went to a new worksheet in Tableau.

I created the below calculations for this sheet;


ValueLabel

Case [Value]

when "Customers" then "CUSTOMERS"

when "Profit" then "PROFIT"

when "Sales" then "SALES"

else "ORDERS"

end


IsSelectedColor

[p_MetricSwap]=[Value]


I changed the Marks type of the sheet to Squares.

I placed the Value dimension on the Columns shelf.

I placed IsselectedColor on the Color marks card.

I also put the TRUE and FALSE calculations on the Detail marks card.

I changed the TRUE color to be a dark grey and the FALSE to be white.

I also removed the default background white shading of the worksheet.



I renamed this sheet KPIBackground.

I placed this background sheet on my dashboard first.

I then floated the KPIText sheet on top of it.



The next thing I needed to do was create a third sheet for the Parameter actions.

This third worksheet just has Value from the AllMetricsList data source on the Columns shelf.

I also changed the marks type of this sheet to a Shape.

On this sheet I also changed the tooltip to "Click here to filter the dashboard by <Value>".

I renamed this third sheet KPIBlank.

I placed this sheet over the other two and made it floating as well.

Now its time for the parameter action.

I set up the action as shown below;



The dashboard is located here for this series in Tableau Public. The other two examples will have instructions in the next couple of weeks!


Commentaires


Subscribe to Tips

If you find my tips useful, please subscribe.

Thanks for submitting!

  • Twitter
  • Facebook
  • Linkedin

© 2023 by BrainStorm. Proudly created with Wix.com

bottom of page