Last Modified Date: 20 Jul 2023
Environment
Tableau DesktopAnswer
The example uses the Superstore sample to create a sparkline that shows sales and profit for various product categories over a long period.
Create the View
- From the Dimensions pane, drag Order Date to the Columns shelf
-
On the Columns shelf, right-click Order Date and select the second instance of Day
Alternatively, if you want to view the profits over four years on a continuous axis, select the second instance of Month.
-
- From the Dimensions pane, drag Category and Segment to the Rows shelf
- From the Measures pane, drag Sales to the Rows shelf
- On the Columns shelf, right-click Month and uncheck Show Header
- On the Rows shelf, right-click Sales and uncheck Show Header
Optional: Add a Text Column for a Measure
- Select Analysis > Create Calculated Field
- In the Calculated Field dialog box that opens, do the following, and then click OK:
- Name the calculated field. In this example, the calculated field is named "Profit per Category per Segment"
- In the formula field, create a calculation similar to the following:
- { EXCLUDE DATETRUNC('day', [Order Date]), [Segment] : SUM([Profit]) }
- Right-click Profit per Category per Segment in the data pane, and select Convert to Discrete
- Drag Profit per Category per Segment to the Rows shelf
Additional Information
A sparkline chart is characterized by its small size and data density. Typically displayed without axes or coordinates, sparklines present trends and variations associated with some measurement, in a simple and condensed way. Whereas the typical chart is designed to show as much data as possible, sparklines are intended to be succinct.Notes on adding a text column for a measure:
- Without the level of detail (LOD) expression EXCLUDE, the SUM(Profit) would return a different value for every day of [Order Date] and every segment, which will create a new row for every different value of profit. The EXCLUDE expression computes SUM(Profit) as if DAY(Order Date) and [Segment] was not included in the view.
- DATETRUNC('day', [Order Date]) was generated by dragging DAY(Order Date) from the Columns shelf after EXCLUDE in the calculation editor.
- All dimensions from the view (except for the dimensions on the Rows shelf) should be added after EXCLUDE
Thank you for providing your feedback on the effectiveness of the article.
Open new Case
Continue Searching
Knowledge Base
Community
Product Help
Training and Tutorials