{"id":620,"date":"2015-12-01T15:39:58","date_gmt":"2015-12-01T15:39:58","guid":{"rendered":"http:\/\/arunethan.com\/?p=620"},"modified":"2015-12-01T16:17:03","modified_gmt":"2015-12-01T16:17:03","slug":"data-label-tricks-tableau","status":"publish","type":"post","link":"http:\/\/arunethan.com\/?p=620","title":{"rendered":"Data Label Tricks &#8211; Tableau"},"content":{"rendered":"<div class=\"pf-content\"><p>Find below conditional data labels, static and dynamic approach<\/p>\n<h2><span style=\"color: #000080;\">Conditional Data Labels\u00a0<\/span><\/h2>\n<pre>(From:\u00a0<a href=\"http:\/\/kb.tableau.com\/articles\/knowledgebase\/conditional-data-labels\">http:\/\/kb.tableau.com\/articles\/knowledgebase\/conditional-data-labels<\/a>)<\/pre>\n<p>One way to display labels based on the values of fields is to drag a measure to Label on the Marks card. However, you might find that you do not want to label every mark; rather, only the outliers, or only the data within your region. Using calculated fields, you can create conditional data labels based on a custom field that includes only the values of interest.<\/p>\n<p>This article shows how to create a conditional label that appears on a mark only when a region\u2019s sales for a day are greater than $100,000.<\/p>\n<h2>Set up the initial view<\/h2>\n<p>Complete the following steps to set up the view for the conditional labels.<\/p>\n<ol>\n<li>Open a new workbook and connect to the Superstore sample.<\/li>\n<li>From the Measures pane, drag <strong>Sales<\/strong> to the <strong>Rows<\/strong> shelf.<\/li>\n<li>From the Dimensions pane, drag <strong>Order Date<\/strong> to the <strong>Columns<\/strong> shelf, and then drag <strong>Region<\/strong> to <strong>Columns<\/strong>.<\/li>\n<li>On the Order Date drop-down menu, select <strong>Day<\/strong>.<\/li>\n<li>Hold down the Ctrl key and drag <strong>SUM(Sales)<\/strong> from <strong>Rows<\/strong> to <strong>Label<\/strong> on the Marks card.<\/li>\n<\/ol>\n<p>The view should look something like this:<\/p>\n<p><img decoding=\"async\" class=\"inline\" src=\"http:\/\/kbcdn.tableausoftware.com\/images\/conditional-data-labels1.png\" alt=\"\" \/><\/p>\n<h2>Create a conditional calculation<\/h2>\n<p>These steps continue from the view you created in the previous section, to build a conditional formula that describes which marks in the view to label.<\/p>\n<h3>Step 1<\/h3>\n<p>Select <strong>Analysis<\/strong> &gt; <strong>Create Calculated Field<\/strong>.<\/p>\n<h3>Step 2<\/h3>\n<p>In the Calculated Field dialog box, complete the following steps.<\/p>\n<ol>\n<li>For <strong>Name<\/strong>, type <strong>Outliers<\/strong>.<\/li>\n<li>In the <strong>Formula<\/strong> box, build the following formula:<code>IF SUM([Sales])&gt; 100000 THEN<br \/>\nSUM([Sales])<br \/>\nELSE null END<\/code><img decoding=\"async\" class=\"inline\" src=\"http:\/\/kbcdn.tableausoftware.com\/images\/conditional-data-labels2.png\" alt=\"\" \/><\/li>\n<li>Confirm that the status message indicates that the formula is valid, and then click <strong>OK<\/strong>.<\/li>\n<\/ol>\n<h3>Step 3<\/h3>\n<p>From the Measures pane, drag <strong>Outliers<\/strong> to <strong>Label<\/strong> on the Marks card, replacing <strong>Sales<\/strong>.<\/p>\n<h3>Step 4<\/h3>\n<p>If necessary, format the numbers as currency.<\/p>\n<p><img decoding=\"async\" class=\"inline\" src=\"http:\/\/kbcdn.tableausoftware.com\/images\/conditional-data-labels3.png\" alt=\"\" \/><\/p>\n<p>The view now includes labels only where sales are greater than $100,000.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Tip:<\/strong> You can show or hide the labels for individual marks. To hide a specific data label, right-click the mark and select <strong>Mark Label<\/strong> &gt; <strong>Never Show<\/strong>.<\/p>\n<p>&nbsp;<\/p>\n<h2><span style=\"color: #000080;\">Conditional Data Labels &#8211; using Parameters<\/span><\/h2>\n<pre>(From:\u00a0<a href=\"http:\/\/vizwiz.blogspot.com\/2011\/11\/tableau-tip-adding-dynamic-top-x-labels.html\">http:\/\/vizwiz.blogspot.com\/2011\/11\/tableau-tip-adding-dynamic-top-x-labels.html<\/a>)<\/pre>\n<p>There a good chance you\u2019ve run into this scenario before, maybe in a past life in Excel or with Tableau:\u00a0 You have a chart with a bunch of bars or columns or maybe a line chart, and you want the top 5 values labeled.\u00a0 Ideally, the chart would look something like this:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"image\" src=\"http:\/\/lh3.ggpht.com\/-jIJdpYXID5w\/TtLynP3MtkI\/AAAAAAAAWsY\/ene8jxtF_zw\/image%25255B14%25255D.png?imgmax=800\" alt=\"image\" width=\"640\" height=\"416\" border=\"0\" \/><\/p>\n<p>With Tableau, you can manually assign labels to these points, but wouldn\u2019t it be better for the points that are labeled to change dynamically based on the data you have selected?\u00a0 There\u2019s no easy way to do this in Tableau, but as always, there\u2019s a workaround that\u2019s quite simple once you implement it once or twice.<\/p>\n<p>Be patient as you read your way through this; it might seem a bit complicated, but I\u2019ll detail every step.\u00a0 Let\u2019s get started.<\/p>\n<p>1. Drag the Order Date dimension onto the Columns shelf, right-click on the pill and choose All Values (This changes the Order Date field from a Discrete dimension to Continuous; not a critical step, simply personal preference)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"image\" src=\"http:\/\/lh5.ggpht.com\/-ev-N28p-_Ao\/TtLyn6y3qDI\/AAAAAAAAWsg\/2Ry5uepFko8\/image%25255B19%25255D.png?imgmax=800\" alt=\"image\" width=\"400\" height=\"271\" border=\"0\" \/><\/p>\n<p>2. Drag the Sales measure onto the Rows shelf (I\u2019ve filtered the Order Date to 2010 only, but that\u2019s not necessary either)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"image\" src=\"http:\/\/lh5.ggpht.com\/-jibGsnGcPwU\/TtLyokBcXbI\/AAAAAAAAWso\/Meu6jvsmQEw\/image%25255B28%25255D.png?imgmax=800\" alt=\"image\" width=\"400\" height=\"366\" border=\"0\" \/><\/p>\n<p>3. Create a parameter, I named mine Top X, with the following properties:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"image\" src=\"http:\/\/lh6.ggpht.com\/-Kve9K5Od4N0\/TtLypE0znpI\/AAAAAAAAWsw\/iSvvQ_VIjT0\/image%25255B34%25255D.png?imgmax=800\" alt=\"image\" width=\"564\" height=\"394\" border=\"0\" \/><\/p>\n<p><strong>NOTE: <\/strong>I could have chosen to always label the top 5 or top 10 values, but I want the consumers of the dashboard to be able to select the number of values they want to see labeled, thus the need for a parameter.<\/p>\n<p>4. Right-click on the \u201cTop X\u201d parameter and choose \u201cCreate Calculated Field\u2026\u201d\u00a0 Name the field \u201cTop X Label\u201d and enter this formula:<\/p>\n<blockquote><p>IF INDEX()&lt;=[Top X] THEN SUM([Sales]) END<\/p><\/blockquote>\n<p>I\u2019ll explain the need to use the INDEX function in a bit.<\/p>\n<p>5. Right-click on the \u201cTop X\u201d parameter and choose \u201cShow Parameter Control\u201d<\/p>\n<p>6. Drag the Top X Label calculated field (from step 4) onto the Label shelf on the Marks card.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"image\" src=\"http:\/\/lh6.ggpht.com\/-aNFmLrtmHKA\/TtLypoERI7I\/AAAAAAAAWs4\/BLhTBIcQF2Q\/image%25255B44%25255D.png?imgmax=800\" alt=\"image\" width=\"160\" height=\"240\" border=\"0\" \/><\/p>\n<p>7. Here comes the trick: Right-click on the Top X Label measure and choose \u201cEdit Table Calculation\u201d<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"image\" src=\"http:\/\/lh4.ggpht.com\/-6EIsZoaHn7g\/TtLyqK6Z8TI\/AAAAAAAAWtA\/kQXkarm-_ck\/image%25255B47%25255D.png?imgmax=800\" alt=\"image\" width=\"255\" height=\"311\" border=\"0\" \/><\/p>\n<p>8. In the Table Calculation dialog box, change the Compute Using option to Advanced<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"image\" src=\"http:\/\/lh6.ggpht.com\/-W2uQQBdTUTU\/TtLyqlmV3fI\/AAAAAAAAWtI\/6CHUGJ6s2s0\/image%25255B50%25255D.png?imgmax=800\" alt=\"image\" width=\"467\" height=\"371\" border=\"0\" \/><\/p>\n<p>9. In the Advanced window, change the Order Along settings to the Sum of Sales Descending.\u00a0 This will force the Top X Label field to index the values based on Sales from highest to lowest (thus the reason the calculated field compares to the INDEX() function).<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"image\" src=\"http:\/\/lh6.ggpht.com\/-lSPFpjKViB8\/TtLyrHIjjaI\/AAAAAAAAWtQ\/x1kU37mzPHY\/image%25255B53%25255D.png?imgmax=800\" alt=\"image\" width=\"465\" height=\"322\" border=\"0\" \/><\/p>\n<p>That\u2019s it!\u00a0 The top 5 points are now labeled. You\u2019re chart should look like this:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"image\" src=\"http:\/\/lh3.ggpht.com\/-ieOZHHyu2bI\/TtLyrqn6esI\/AAAAAAAAWtY\/ALQ_GaHlWUI\/image%25255B57%25255D.png?imgmax=800\" alt=\"image\" width=\"640\" height=\"390\" border=\"0\" \/><\/p>\n<p>You can use the Top X parameter to pick the number of values you want to label.\u00a0 Even if you filter the data, maybe to only show the East Region, the labels will still work properly.<\/p>\n<p>But this is Tableau, so let\u2019s take it a step farther.\u00a0 Maybe you need to label the top 5 <strong><em>and<\/em><\/strong> the bottom 5.\u00a0 There\u2019s a neat little way to do this too.<\/p>\n<p>1. Duplicate the Top X parameter and rename it Bottom Y and the show the Bottom Y parameter control<\/p>\n<p>2. Duplicate the Top X Label calculated field, update it to reference the Bottom Y parameter and rename it to Bottom Y label:<\/p>\n<blockquote><p>IF INDEX()&lt;=[Bottom Y] THEN SUM([Sales]) END<\/p><\/blockquote>\n<p>So now what?\u00a0 There\u2019s no way to add a second label!\u00a0 True, but there <strong><em>IS<\/em><\/strong> a way to add a secondary axis.<\/p>\n<p>3. Drag Sales onto the Rows shelf, right-click on it and choose Dual Axis<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"image\" src=\"http:\/\/lh4.ggpht.com\/-rxdk4S5SIz4\/TtLysMClHgI\/AAAAAAAAWtg\/dKKJSOUpnAk\/image%25255B61%25255D.png?imgmax=800\" alt=\"image\" width=\"400\" height=\"280\" border=\"0\" \/><\/p>\n<p>4. Remove \u201cMeasure Names\u201d from the color shelf (we don\u2019t need different colors since we\u2019re using the same measure twice)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"image\" src=\"http:\/\/lh3.ggpht.com\/-i3qwCfpAVU0\/TtLysu_q8eI\/AAAAAAAAWto\/TpPtSss0Nss\/image%25255B64%25255D.png?imgmax=800\" alt=\"image\" width=\"226\" height=\"233\" border=\"0\" \/><\/p>\n<p>5. On the Marks card, click on the carrot on the upper-right of the card and choose Multiple Mark Types<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"image\" src=\"http:\/\/lh4.ggpht.com\/--x8q_WMJxpI\/TtLytFYBd8I\/AAAAAAAAWtw\/Oom1X5V1NzU\/image%25255B67%25255D.png?imgmax=800\" alt=\"image\" width=\"158\" height=\"233\" border=\"0\" \/><\/p>\n<p>6. Click the right arrow twice until you see \u201cSUM(Sales) (2)\u201d, then drag the Bottom Y Labels calculated field onto the Label shelf<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"image\" src=\"http:\/\/lh3.ggpht.com\/-POR9aMx6hRQ\/TtLytvEqq1I\/AAAAAAAAWt4\/k_BwoGRkeHA\/image%25255B70%25255D.png?imgmax=800\" alt=\"image\" width=\"158\" height=\"262\" border=\"0\" \/><\/p>\n<p>7. Right-click on the Bottom Y Labels field, choose Edit Table Calculation, then repeat steps 8 &amp; 9 above.\u00a0 The only difference is that the advanced table calculation should be in ascending order for the Bottom Y Labels:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"image\" src=\"http:\/\/lh4.ggpht.com\/-uWu7S4WAlxU\/TtLyuCZxyBI\/AAAAAAAAWuA\/l21kxiJFRxE\/image%25255B73%25255D.png?imgmax=800\" alt=\"image\" width=\"465\" height=\"67\" border=\"0\" \/><\/p>\n<p>You\u2019re done!\u00a0 You now have an interactive chart that allows the user to pick the number of top and bottom values they want to see.\u00a0 Interact with it, download it and see how it works for yourself.<\/p>\n<p><a href=\"https:\/\/public.tableau.com\/views\/TopXBottomY_0\/TopXBottomY?:embed=y&amp;:display_count=yes&amp;:showTabs=y\">https:\/\/public.tableau.com\/views\/TopXBottomY_0\/TopXBottomY?:embed=y&amp;:display_count=yes&amp;:showTabs=y<\/a><\/p>\n<p>&nbsp;<\/p>\n<p><script src=\"https:\/\/public.tableau.com\/javascripts\/api\/viz_v1.js\" type=\"text\/javascript\"><\/script><\/p>\n<div class=\"tableauPlaceholder\" style=\"width: 522px; height: 442px;\"><noscript><a href='#'><img alt='YTD Top 5 and Bottom 5 Sales Days ' src='https:&#47;&#47;public.tableau.com&#47;static&#47;images&#47;To&#47;TopXBottomY_0&#47;TopXBottomY&#47;1_rss.png' style='border: none' \/><\/a><\/noscript><object class=\"tableauViz\" style=\"display: none;\" width=\"522\" height=\"442\"><param name=\"host_url\" value=\"https%3A%2F%2Fpublic.tableau.com%2F\" \/><param name=\"site_root\" value=\"\" \/><param name=\"name\" value=\"TopXBottomY_0\/TopXBottomY\" \/><param name=\"tabs\" value=\"no\" \/><param name=\"toolbar\" value=\"yes\" \/><param name=\"static_image\" value=\"https:\/\/public.tableau.com\/static\/images\/To\/TopXBottomY_0\/TopXBottomY\/1.png\" \/><param name=\"animate_transition\" value=\"yes\" \/><param name=\"display_static_image\" value=\"yes\" \/><param name=\"display_spinner\" value=\"yes\" \/><param name=\"display_overlay\" value=\"yes\" \/><param name=\"display_count\" value=\"yes\" \/><param name=\"showVizHome\" value=\"no\" \/><param name=\"showTabs\" value=\"y\" \/><param name=\"bootstrapWhenNotified\" value=\"true\" \/><\/object><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Find below conditional data labels, static and dynamic approach Conditional Data Labels\u00a0 (From:\u00a0http:\/\/kb.tableau.com\/articles\/knowledgebase\/conditional-data-labels) One way to display labels based on the values of fields is to drag a measure to Label on the Marks&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":622,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[105],"tags":[102,101],"_links":{"self":[{"href":"http:\/\/arunethan.com\/index.php?rest_route=\/wp\/v2\/posts\/620"}],"collection":[{"href":"http:\/\/arunethan.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/arunethan.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/arunethan.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/arunethan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=620"}],"version-history":[{"count":7,"href":"http:\/\/arunethan.com\/index.php?rest_route=\/wp\/v2\/posts\/620\/revisions"}],"predecessor-version":[{"id":628,"href":"http:\/\/arunethan.com\/index.php?rest_route=\/wp\/v2\/posts\/620\/revisions\/628"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/arunethan.com\/index.php?rest_route=\/wp\/v2\/media\/622"}],"wp:attachment":[{"href":"http:\/\/arunethan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=620"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/arunethan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=620"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/arunethan.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=620"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}