相关文章推荐
小百科
›
Data Aggregation in Tableau - Tableau
tableau
玩篮球的创口贴
1 年前
</noscript><div id="app" class="wrapper"><header id="tableau-help-article-header" class="container--full-width quick-help-header"><div class="container--centered"><div class="header__mobile-menu quick-help-hidden"><menu-tree-toggle/></div><div class="header__logo quick-help-hidden"><a href="https://www.tableau.com/en-us/"><img src="./Resources/tableau-logo.png" class="header__logo__img" alt="Tableau"/></a></div><div class="header__search"><search-header-help placeholder="Search"/></div></div></header><div class="container--navigation-top quick-help-hidden content-only-hidden"><div id="help-subheader" class="subheader print-hidden"><div class="container--centered"><h4 class="heading--subheader">Tableau Desktop and Web Authoring Help</h4></div></div><div class="container--top-links"><div class="container--centered container--breadcrumbs"><div><breadcrumb-links-help/></div></div><div id="help-container-menu-headings" class="container--menu-headings"><nav class="nav-medium-screen"><menu-heading-links-static-help menu-title="In this article" :disabled="false" :headings="pageHeadings"/></nav></div></div></div><div class="section--main container--full-width"><div class="container--centered"><nav class="nav-side nav-side--left" role="navigation"><menu-tree-help menu-title="Contents"/></nav><article role="main"><h1 id="contentH1">Data Aggregation in Tableau</h1><div class="caption article__tags content-only-hidden quick-help-hidden"><span class="article__tags--applies-to">Applies to: Tableau Desktop</span><br/><span class="article__tags--role"> </span></div><div id="content-body"> <p>In Tableau, you can aggregate measures or dimensions, though it’s more common to aggregate measures. Whenever you add a measure to your view, an aggregation is applied to that measure by default. The type of aggregation applied varies depending on the context of the view.</p> <h2 is="heading-item" :level="2" id="change-the-aggregation-of-a-measure-in-the-view"><a name="Measures"/>Change the Aggregation of a Measure in the View</h2> <p>When you add a measure to the view, Tableau automatically aggregates its values. Sum, average, and median are common aggregations; for a complete list, see <a href="#AggFuncs" class="MCXref xref">List of Predefined Aggregations in Tableau</a>. </p> <p>The current aggregation appears as part of the measure's name in the view. For example, <span class="uicontrol">Sales</span> becomes <span class="uicontrol">SUM(Sales)</span>. Every measure has a default aggregation that is set by Tableau when you connect to a data source. You can view or change the default aggregation for a measure—see <a href="#DefaultAgg" class="MCXref xref">Set the Default Aggregation for a Measure</a>.</p> <p class="note">You can aggregate measures using Tableau only for <span class="ph">relational data sources</span>. Multidimensional data sources contain data that is already aggregated. In Tableau, multidimensional data sources are supported only in Windows. </p> <p>You can change the aggregation for a measure in the view from its context menu:</p> <h2 is="heading-item" :level="2" id="aggregating-dimensions"><a name="Dims"/>Aggregating Dimensions</h2> <p>You can aggregate a dimension in the view as <span class="uicontrol">Minimum</span>, <span class="uicontrol">Maximum</span>, <span class="uicontrol">Count</span>, or <span class="uicontrol">Count (Distinct)</span>. When you aggregate a dimension, you create a new temporary measure column, so the dimension actually takes on the characteristics of a measure.</p> <p>Another way to view a dimension is to treat it as an Attribute by choosing <span class="uicontrol">Attribute </span>from the context menu for the dimension. The <span class="uicontrol">Attribute</span> aggregation has several uses:</p> <li>It can ensure a consistent level of detail when blending multiple data sources.</li> <li>It can provide a way to aggregate dimensions when computing table calculations, which require an aggregate expression.</li> <li>It can improve query performance because it’s computed </li> <p>Tableau computes Attribute using the following formula:</p> <p><code>IF MIN([dimension]) = MAX([dimension]) THEN MIN([dimension]) ELSE "*" END</code> <p>The formula is computed in Tableau after the data is retrieved from the initial query. The asterisk (*) is actually a visual indicator of a special type of Null value that occurs when there are multiple values. See <a href="multipleconnections_troubleshooting.htm" target="_blank" class="MCXref xref">Troubleshoot Data Blending<span class="sr-only">(Link opens in a new window)</span></a> to learn more about the asterisk.</p> <p>Here is an example of using Attribute in a table calculation. The table shows sales by market, market size, and state. Suppose you wanted to compute the percent of total sales each state contributed to the market. When you add a Percent of Total quick table calc (see <a href="calculations_tablecalculations_quick.htm" target="_blank" class="MCXref xref">Quick Table Calculations<span class="sr-only">(Link opens in a new window)</span></a>) that computes along State, the calculation computes within the red area. This is because the Market Size dimension is partitioning the data.</p> <p>When you aggregate Market Size as an Attribute, the calculation is computed within the Market (East, in the following image), and Market Size is purely as a label.</p> <h2 is="heading-item" :level="2" id="list-of-predefined-aggregations-in-tableau"><a name="AggFuncs"/>List of Predefined Aggregations in Tableau</h2> <p>Sometimes it’s useful to look at numerical data in an aggregated form such as a sum or an average. The mathematical functions that produce aggregated data are called aggregation functions. Aggregation functions perform a calculation on a set of values and return a single value. For example, a measure that contains the values 1, 2, 3, 3, 4 aggregated as a sum returns a single value: 13. Or if you have 3,000 sales transactions from 50 products, you might want to view the sum of sales per product to determine which products have the highest revenue.</p> <p class="note"><b>Note</b>: Using floating-point values with aggregations can sometimes lead to unexpected results. For details, see <a href="functions_operators.htm#Data" target="_blank" class="MCXref xref">Understanding data types in calculations<span class="sr-only">(Link opens in a new window)</span></a>.</p> <p>Tableau provides a set of predefined aggregations that are shown in the table. You can set the default aggregation for any measure that isn’t a calculated field that itself contains an aggregation, such as <code>AVG([Discount])</code>. See <a href="#DefaultAgg" class="MCXref xref">Set the Default Aggregation for a Measure</a>. You can also set the aggregation for a field already in the view. For details, see <a href="#Measures" class="MCXref xref">Change the Aggregation of a Measure in the View</a>. </p><table class="Basic-NoTitle" style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left: none; border-right: none; border-collapse: collapse;"><colgroup><col title="1" style="width: 20%;"/><col title="2" style="width: 60%;"/><col title="3" style="width: 20%;"/></colgroup><thead><tr><th style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray; border-left: none;">Aggregation</th><th style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray;">Description</th><th style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray; border-right: none;">Result for measure that contains 1, 2, 2, 3</th></tr></thead><tbody><tr><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray; border-left: none;">Attribute</td><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray;"><p>Returns the value of the given expression if it only has a single value for all rows in the group, otherwise it displays an asterisk (*) character. Null values are ignored. This aggregation is useful when aggregating a dimension. To set a measure in the view to this aggregation, right-click (control-click on Mac) the measure and choose <span class="uicontrol">Attribute</span>. The field then changes to show the text ATTR:</p><p><img src="Img/calc_agg_attr.png" alt=""/></p></td><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray; border-right: none;">* </td></tr><tr><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray; border-left: none;">Dimension</td><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray;">Returns all unique values in a measure or dimension.</td><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray; border-right: none;">3 values (1, 2, 3)</td></tr><tr><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray; border-left: none;">Sum</td><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray;">Returns the sum of the numbers in a measure. Null values are ignored.</td><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray; border-right: none;">1 value (8)</td></tr><tr><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray; border-left: none;">Average</td><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray;">Returns the arithmetic mean of the numbers in a measure. Null values are ignored.</td><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray; border-right: none;">1 value (2)</td></tr><tr><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray; border-left: none;">Count (Distinct)</td><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray;"><p>Returns the number of unique values in a measure or dimension. When applied to a dimension, Tableau creates a new temporary column that is a measure because the result of a count is a number. You can count numbers, dates, booleans, and strings. Null values are ignored in all cases. </p><p>This aggregation isn’t available for the following types of workbooks:</p><ul><li>Workbooks created before Tableau Desktop 8.2 and that use Microsoft Excel or Text File data sources.</li><li>Workbooks that use legacy connections. </li><li>Workbooks that use Microsoft Access data sources.</li></ul><p data-mc-conditions="Product.desktoppro">If you’re connected to a workbook that uses of one of these types, Count (Distinct) is unavailable and Tableau shows the message "Requires extract." To use this aggregation, extract your data. See <a href="extracting_data.htm" class="MCXref xref">Extract Your Data</a>.</p></td><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray; border-right: none;">1 value (3)</td></tr><tr><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray; border-left: none;">Minimum</td><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray;">Returns the smallest number in a measure or continuous dimension. Null values are ignored.</td><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray; border-right: none;">1 value (1)</td></tr><tr><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray; border-left: none;">Maximum</td><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray;">Returns the largest number in a measure or in the given expression based on a sample population. Null values are ignored. Returns a Null if there are fewer than 2 members in the sample that aren’t Null. Use this function if your data represents a sample of the population.</td><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray; border-right: none;">1 value (3)</td></tr><tr><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray; border-left: none;">Std. Dev (Pop.)</td><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray;">Returns the standard deviation of all values in the given expression based on a biased population. Assumes that its arguments consist of the entire population. Use this function for large sample sizes.</td><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray; border-right: none;">1 value (0.7071)</td></tr><tr><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray; border-left: none;">Variance</td><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray;">Returns the variance of all values in the given expression based on a sample. Null values are ignored. Returns a Null if there are fewer than 2 members in the sample that are not Null. Use this function if your data represents a sample of the population.</td><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray; border-right: none;">1 value (0.6667)</td></tr><tr><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray; border-left: none;">Variance (Pop.)</td><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray;">Returns the variance of all values in the given expression based on a biased population. Assumes that its arguments consist of the entire population. Use this function for large sample sizes.</td><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray; border-right: none;">1 value (0.5000)</td></tr><tr><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray; border-left: none;">Disaggregate</td><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray;"><p>Returns all records in the underlying data source. To disaggregate all measures in the view, select <span class="uicontrol">Aggregate Measures</span> from the Analysis menu (to clear the check mark). </p><p>Tableau allows you to view data in disaggregated form (relational databases only). When data are disaggregated, you can view the individual rows of your data source. For example, after discovering that the sum of sales for rubber bands is $14,600, you might want to see the distribution of individual sales transactions. To answer this question, you must create a view that shows individual rows of data. That is, you must disaggregate the data (see <a href="#DisAggData" class="MCXref xref">How to Disaggregate Data</a>). Another way to look at disaggregated data is to view the underlying data for all or part of a view. For more details, see <a href="inspectdata_viewdata.htm" class="MCXref xref">View Underlying Data</a>.</p></td><td style="border-top-style: solid; border-top-width: thin; border-top-color: gray; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: gray; border-left-style: solid; border-left-width: thin; border-left-color: gray; border-right-style: solid; border-right-width: thin; border-right-color: gray; border-right: none;">4 values (1, 2, 2, 3)</td></tr></tbody></table> <p>You can also define custom aggregations as described in <a href="calculations_calculatedfields_aggregate_create.htm" target="_blank" class="MCXref xref">Aggregate Functions in Tableau<span class="sr-only">(Link opens in a new window)</span></a>. Depending on the type of data view you create, Tableau applies these aggregations at the appropriate level of detail. For example, Tableau applies the aggregation to individual dimension members (the average delivery time in the East region), all members in a given dimension (the average delivery time in the East, West, and Central regions), or groups of dimensions (the sum of sales for all regions and for all markets).</p> <h2 is="heading-item" :level="2" id="set-the-default-aggregation-for-a-measure"><a name="DefaultAgg"/>Set the Default Aggregation for a Measure</h2> <p>You can set the default aggregation for any measure that isn’t a calculated field that itself contains an aggregation, such as <code>AVG([Discount])</code>. A default aggregation is a preferred calculation for summarizing a continuous or discrete field. The default aggregation is automatically used when you drag a measure to a view. </p> <p style="font-weight: bold;">To change the default aggregation:</p> <p>Right-click (control-click on Mac) a measure in the Data pane and select <span class="uicontrol">Default Properties</span> > <span class="uicontrol">Aggregation</span>, and then select one of the aggregation options. <p class="note"><b>Note</b>: You can use Tableau to aggregate measures only with <span class="ph">relational data sources</span>. Multidimensional data sources contain aggregated data only.<br/><br/>You can’t set default aggregations for published data sources. The default aggregation is set when the data source is initially published. <a href="http://kb.tableau.com/articles/howto/edit-a-published-data-source" target="_blank">Create a Local Copy<span class="sr-only">(Link opens in a new window)</span></a> of the published data source to adjust the default aggregation.</p> <h2 is="heading-item" :level="2" id="how-to-disaggregate-data"><a name="DisAggData"/>How to Disaggregate Data</h2> <p>Whenever you add a measure to your view, an aggregation is applied to that measure by default. This default is controlled by the <span class="uicontrol">Aggregate Measures</span> setting in the <span class="uicontrol">Analysis</span> menu. </p> <p>If you decide you want to see all the marks in the view at the most detailed level of granularity, you can disaggregate the view. Disaggregating your data means that Tableau displays a separate mark for every data value in every row of your data source. </p> <p style="font-weight: bold;">To disaggregate all measures in the view:</p> <p>Clear the <span class="uicontrol">Analysis >Aggregate Measures</span> option. If it’s already selected, click <span class="uicontrol">Aggregate Measures</span> one time to deselect it.</p> <p>When <span class="uicontrol">Aggregate Measures</span> is selected, Tableau attempts to aggregate measures in the view by default. Individual row values from your data source are aggregated into a single value (a single mark) at the level of detail in your view. </p> <p>The different aggregations available for a measure determine how the individual values are collected: they can be added (SUM), averaged (AVG), or set to the maximum (MAX) or minimum (MIN) value from the individual row values. </p> <p>For a complete list of the available aggregations, <a href="#AggFuncs" class="MCXref xref">List of Predefined Aggregations in Tableau</a>. </p> <p>The level of detail is determined by the dimensions in your view—for information about the concept of level of detail, see <a href="datafields_typesandroles.htm#DimLOD" class="MCXref xref">How dimensions affect the level of detail in the view</a>.</p> <p>Disaggregating your data can be useful for analyzing measures that you may want to use both independently and dependently in the view. For example, you may be analyzing the results from a product satisfaction survey with the Age of participants along one axis. You can aggregate the <span class="uicontrol">Age</span> field to determine the average age of participants or disaggregate the data to determine at what age participants were most satisfied with the product.</p> <p>Disaggregating data can be useful when you’re viewing data as a scatter plot. See <a href="#ExampleScatter" class="MCXref xref">Example: Scatter Plots, Aggregation, and Granularity</a>.</p> <p class="note"><b>Note:</b> If your data source is very large, disaggregating the data can result in a significant performance degradation.</p> <h2 is="heading-item" :level="2" id="example-scatter-plots-aggregation-and-granularity"><a name="ExampleScatter"/><a name="top2"/>Example: Scatter Plots, Aggregation, and Granularity</h2> <p>If you place one measure on the <span class="uicontrol">Rows </span>shelf and another measure on the <span class="uicontrol">Columns </span>shelf, you’re asking Tableau to compare two numerical values. Typically, Tableau chooses a scatter plot as the default visualization in such cases. The initial view will most likely be a single mark, showing the sum for all values for the two measures. This is because you must increase the level of detail in the view.</p> <p><a href="#InitialView" class="MCXref xref">Start building the scatter plot</a> <p><a href="#DimOnDetail" class="MCXref xref">Use dimensions to add detail</a> <p><a href="#RowColOpt2" class="MCXref xref">Try adding more fields to the rows and columns shelves</a> <p><a href="#TryDisAgg" class="MCXref xref">Try disaggregating the data</a> <h3 is="heading-item" :level="3" id="start-building-the-scatter-plot"><a name="InitialView"/>Start building the scatter plot</h3> <p>There are various ways to add detail to a basic scatter plot: <b>you can use dimensions to add detail</b>, you can add more fields to the Rows and Columns shelves, or you can <b>disaggregate the data</b>. You can also use any combination of these options. This topic looks at these alternatives using the <b>Sample-Superstore</b> data source. </p> create the initial view, follow these steps:</p> <p>Place the <span class="uicontrol">Sales </span>measure on the <span class="uicontrol">Columns</span> shelf.</p> <p>Place the <span class="uicontrol">Profit</span> measure on the <span class="uicontrol">Rows</span> shelf.</p> measures are automatically aggregated as sums. The default aggregation (SUM) is indicated in the field names. The values shown in the tooltip show the sum of sales and profit values across every row in the data source.</p> <p>Follow these steps to use dimensions to add detail to the view and to disaggregate data.</p> <h3 is="heading-item" :level="3" id="use-dimensions-to-add-detail"><a name="DimOnDetail"/>Use dimensions to add detail</h3> <p>Follow these steps to develop the scatter plot view you created by adding dimensions to show more levels of detail.</p> <p>Drag the <span class="uicontrol">Category</span> dimension to <span class="uicontrol">Color</span> on the Marks card.</p> separates the data into three marks—one for each dimension member—and encodes the marks using color.</p> <p>Although more marks are now displayed, the measures are still aggregated. So regardless of whether there’s one row in the data source where State = North Dakota and Category= Furniture, or 100 such rows, the result is always a single mark.</p> <p>Maybe this process is developing the view in a direction you find useful, or maybe you prefer to go in a different direction. You decide what questions to ask.</p> <h3 is="heading-item" :level="3" id="try-adding-more-fields-to-the-rows-and-columns-shelves"><a name="RowColOpt2"/>Try adding more fields to the rows and columns shelves</h3> <p>Revert to the original one-mark view and follow these steps to develop the scatter plot view by adding fields to the <span class="uicontrol">Rows </span>and <span class="uicontrol">Columns </span>shelves.</p> <p>Drag the <span class="uicontrol">State</span> dimension to the <span class="uicontrol">Columns</span> shelf.</p> <p>Even if you drop <span class="uicontrol">Continent</span> to the right of <span class="uicontrol">SUM(Sales)</span>, Tableau moves it to the left of <span class="uicontrol">SUM(Sales)</span>. This is because you can’t insert a dimension within a continuous axis. Instead, your view shows a separate axis for each member of the dimension.</p> <h3 is="heading-item" :level="3" id="try-disaggregating-the-data"><a name="TryDisAgg"/>Try disaggregating the data</h3> <p>Another way to modify your original one-mark scatter plot to display more marks is by disaggregating the data. </p> <p>Clear the <span class="uicontrol">Analysis >Aggregate Measures</span> option. If it’s already selected, click <span class="uicontrol">Aggregate Measures</span> one time to deselect it.</p> <p>What you have done is to dis-aggregate the data, because this command is a switch that was originally selected (check mark present). Tableau aggregates data in your view by default. </p> <p>Now you see many marks—one for each row in your original data source: </p>
推荐文章