Previous Value Function in Tableau - CNDRO.LLC
2757
post-template-default,single,single-post,postid-2757,single-format-standard,wp-custom-logo,theme-bridge,bridge-core-2.9.4,woocommerce-no-js,tribe-no-js,ehf-template-bridge,ehf-stylesheet-bridge-child,qode-page-transition-enabled,ajax_fade,page_not_loaded,,qode-title-hidden,qode_grid_1300,footer_responsive_adv,hide_top_bar_on_mobile_header,columns-4,qode-child-theme-ver-1.0.0,qode-theme-ver-27.8,qode-theme-bridge,qode_header_in_grid,wpb-js-composer js-comp-ver-6.7.0,vc_responsive,elementor-default,elementor-kit-2634

Previous Value Function in Tableau

At the beginning of my Tableau Journey back then in 2018, I was going through a goal news edition and I came across something similar to the image below.

I thought about it, what if I can do something similar in Tableau with the previous function. So, I jumped onto Tableau with sample superstore to see the possibilities of this. It was surprising to see * in tooltip whenever the list of items per region exceeded 1.

Previous value in Tableau

I was cool and happy with the screenshot above but got surprised with the screenshot below;

I got that asterisk because Tableau is trying to aggregate by using (ATTR) and ATTR returns a returns value if it has a single value for all the rows else it throws it out *. I love investigating stuff, so I traced what this could be to how many products we have per state.

Notice that we have 103 marks which indicate 103 products (since this is more than one, the asterisk should be expected according to its definition).

Enough talking and let’s get down to the solution. With Tableau’s previous function we could build something similar to what I wanted. Here is a quick glance at Tableau’s definition of the Previous Function; returns the value of this calculation in the previous row.

Calculated Field

  1. IF FIRST () =0 THEN MIN ([Product Name]) ELSE PREVIOUS_VALUE (MIN ([Product Name])) + ‘ ,’ +MIN ([Product Name]) END
  2. LAST () = 0

Tableau worksheet.

  1. Build the bar chart by dragging States to row and sales to column.

2. Build another worksheet that will be used as a tooltip in the bar chart, here is where we will use the two calculated fields.

a. Create a new sheet

b. Drag States to row, followed by product names, then drag the first calculated field to row.

c. Compute the Table Calculation using Product Name as shown below.

3. Also drag the second calculated field to row, then compute using Product name as shown above.

4. Hold Ctrl and drag the second calculated field to filter, then check True.

5. Go back to the bar chart worksheet, click on the tooltip and insert the second worksheet you just built.

6. Hover on each bar to see if your tooltip is working fine. Then format to your taste.

Now that you know how the Previous value function works in Tableau, you can go ahead to try your hands on it. If you have any more questions, feel free to ask in the comment box. Thanks for reading.

No Comments

Post A Comment