0% found this document useful (0 votes)
4 views5 pages

Session 4.5

Uploaded by

no one
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

Session 4.5

Uploaded by

no one
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

CREATING A CALCULATED FIELDS FOR DEEPER ANALYSIS : WORKING

WITH AGGREGATE FUNCTIONS


SESSION 4
Section 5 of 6

Understand automatic aggregation and aggregate functions


Aggregation refers to how data is combined, such as summing the number of souvenirs sold
at a baseball game, or taking the average water use of all households in a district.

When you bring a measure into a view, Tableau automatically aggregates the values in that
field and represents it according to the level of detail in the view. When you bring two
measures into the view, Tableau also aggregates the measures and finds a point where the
aggregations intersect.

But, what if changing the default aggregation of a measure does not meet your needs? For
example, maybe you want to compare the total and average sales within a single view, or you
want a field that shows average sales to reuse in multiple views.

In cases like these, you can use an aggregate function in a calculation to create the calculated
field, Average Sales.

Aggregate functions allow you to summarize data by performing a calculation on a set of


values at the level of detail in a view and then returning a single value.

Knowledge Check 5.1


1. Which of the following expressions will return the value of 17 for the number of cakes
sold?

a. MAX ([Cakes sold])


b. AVG ([Cakes sold])
c. MIN ([Cakes sold])
d. SUM ([Cakes sold])
Try it! Use aggregate functions in a profit ratio calculation
Scenario
Your data contains fields for the Profit and Sales of your company’s products, and you want
to see the profit ratios for each year, broken down by Category. You don’t have a Profit
Ratio field in your data, so you will need to create one with a calculated field.

First create the calculation without aggregating the fields, change the number format from a
decimal to a percentage, and then aggregate each field in the calculation to see how the
results change.

1. Open the “Create a Calculation with Aggregation - Starter” file in Tableau


2. Create a view that displays the total profit by Category and Year of Order Date,
with Profit shown in color and as a text label.
1. From the Data pane:
a. Drag Category to Columns.
b. Drag Order Date to Rows.
c. Drag Profit to Color on the Marks card.
2. On the Analysis menu, click Show Mark Labels.
3. Create a Profit Ratio field using a row-level calculation and add it to the view,
replacing Profit.
1. At the top of the Data pane, click the drop-down arrow and then click Create
Calculated Field. Alternatively, select Create Calculated Field from
the Analysis menu.
2. In the calculation editor, type “Profit Ratio” in the name field.
3. Enter this formula: [Profit] / [Sales]
4. Click OK.
5. From the Data pane, drag the Profit Ratio field to the Marks card and drop it
on the Profit field, replacing it.

4. Set the Profit Ratio field’s format as a percentage with 1 decimal place.
1. In the Data pane, right-click Profit Ratio, point to Default Properties, and
then click Number Format.
2. In the Default Number Format [Profit Ratio] dialog box,
click Percentage and set Decimal places to 1.
3. Click OK to apply the change and close the dialog box.
5. Use the view you’ve assembled so far to answer the following question.
Knowledge Check 5.2
1. According to the row-level calculation you created, what is the lowest profit
percentage in the view?
a. 1874.5%
b. 1486.6%
c. 14.9
d. 42912.7%

6. Edit the Profit Ratio calculated field to aggregate Profit and Sales separately. Then
drag the edited Profit Ratio field to the Marks card and drop it directly over the
previous calculation to replace it and repair the view.
1. In the Data pane, right-click Profit Ratio, and click Edit.
2. In the calculation editor, edit the calculation to: SUM ([Profit]) / SUM
([Sales])
3. Click OK. The field on the Marks card will turn red, and the view will fade.
4. From the Data pane, drag the edited Profit Ratio field to the Marks card and
drop it on SUM(Profit Ratio), replacing it.
Note: In Tableau Desktop, the field will remain formatted as a percentage. In
Tableau Server and Tableau Cloud, you will need to reformat it as a
percentage.

Knowledge Check 5.3


1. What was the profit ratio for Office Supplies in 2019?
a. 13.4%
b. 524.6%
c. 19.1%
d. 25194.3%

You might also like