When we talk about Level of Detail (LOD) calculations in Tableau, we mean three expressions: FIXED, INCLUDE, and EXCLUDE. These three expressions open a world of options by providing the ability to create calculations that target针对 specific levels of granularity. In older versions of Tableau, data granularity数据粒度 for a worksheet was established by the dimensions in a view. If the view contained dimensions for, for example, Region, State, and Postal Code, but the author wanted to create a City -level calculation, the City dimension would need to be included on the view. Furthermore, there was no mechanism for excluding or ignoring a given dimension on a view. Admittedly, the desired results could normally be obtained through some complex and sometimes convoluted use of table calculations, data blends, and so on. Fortunately, LOD calculations greatly simplify these use case scenarios and, in some cases, enable what was previously impossible.

In this chapter, we will discuss the following topics:

  • • Introducing LOD calculations
  • • Playground I: FIXED and EXCLUDE
  • • Playground II: INCLUDE
  • • Building practical applications with LOD

Let's begin by introducing LOD calculations and how they are used.

Introducing LOD calculations

Tableau's default is to show measures in a view based on the dimensions also present in the view.

  • If you have a dashboard with Sales data and dimensions like State and City, and you drag the State and Sales data onto the view, the Sales data will be divided by State, showing you Sales per State.
  • If you want to divide the Sales data further into smaller chunks, you might add the City field, resulting in Sales data per City, per State.

LOD calculations can manipulate this default behavior. After completing this chapter, you will be able to divide or partition measures by dimensions that are not in the view and show measures using fewer dimensions than are visible in the view.

To do this, we will build and use two playgrounds. Delivering reports as required by one's job duties may lead to a thorough knowledge of a limited set of capabilities; that is, a deep but narrow understanding. It can be difficult to set aside time (and also justify that time) to explore the capabilities of Tableau that on the surface may seem to have no direct correlation to job duties. Playground environments can help overcome any difficulties and objections, by providing efficient avenues of exploration探索途径. In this chapter, we'll build two playground environments specifically for LOD calculations, to help make the task of deep and broad understanding easier by providing an efficient avenue for exploration and understanding. You can always come back to the workbook accompanying this chapter and test functionality related to LODs.

Playground I: FIXED and EXCLUDE

The first playground we will build will be for the purpose of exploring two of the three LOD functions: FIXED and EXCLUDE. We will use a set of parameters and associated calculated fields to efficiently explore how these functions work.

Setting up the workbook

Much of the groundwork for this exercise has already been completed in the workbook associated with this chapter. The steps require more so to open different calculations and parameters and see how they have been set up and why this works. Explanations are given along the way. If you do not have ready access to the workbook, you should be able to construct a similar one by referencing the following information.

To complete the initial setup of a worksheet, take the following steps:

  • 1. Navigate to https://public.tableau.com/app/profile/marleen.meier to locate and download the workbook associated with this chapter.
    ==>==>Add to Context
    Once the filter is selected as a context filter, the color of dimension box changes to grey color. This grey color box is an indication of context filter.
  • 2. Open the workbook associated with this chapter and navigate to the Fixed and Exclude worksheet. The worksheet should look as follows:
  • 3. Select the Superstore data source and inspect the parameter named 1st Dim by right-clicking and selecting Edit:

    The parameters named 2nd Dim, 3rd Dim, and 4th Dim are identical to 1st Dim.
  • 4. Note that except for Order Date and Ship Date, every dimension in the dataset is included in the list of values (see Figure 7.2). For the purposes of this exercise, Category, Region, Segment, Ship Mode, and Sub-Category are particularly important because those are dimensions with fewer members. Dimensions with many members are more difficult to use in this context.
  • 5. Inspect the Choose Fixed Dims, Choose Excluded Dims 1, and Choose Excluded Dims 2 parameters included in the workbook and note that we defined a number of integers under the Value column, each of which will later be visible as a string specified under the Displays As column in the parameter dropdown. The Value and Display As configurations for Choose Fixed Dims are as follows:
  • 6. Inspect the calculated field named 1st Dim (it is located under the Practical: All folder in the Data pane); this calculation makes use of the 1st Dim parameter and will cause a field to be displayed depending on the selection of the parameter.
         If the user selects Category in the 1st Dim parameter, value 1 will be activated (according to the values specified in Figure 7.2). Value 1 then translates to the field Category in the calculated field 1st Dim as shown in the following screenshot:

    CASE [Parameters].[1st Dim]
    WHEN 1 THEN [Category]
    WHEN 2 THEN [City]
    WHEN 3 THEN [Country]
    WHEN 4 THEN [Customer ID]
    WHEN 5 THEN [Customer Name]
    WHEN 6 THEN [Order ID]
    WHEN 7 THEN STR( [Postal Code] )
    WHEN 8 THEN  [Product ID]
    WHEN 9 THEN [Product Name]
    WHEN 10 THEN [Region]
    WHEN 11 THEN [Segment]
    WHEN 12 THEN [Ship Mode]
    WHEN 13 THEN [State]
    WHEN 14 THEN [Sub-Category]
    WHEN 15 THEN ""
    END

  • 7. The calculated fields named 2nd Dim, 3rd Dim, and 4th Dim are identical to 1st Dim except that each references the parameter bearing its name; for example, the 2nd Dim calculated field utilizes [Parameters].[2nd Dim].

    These Case statements, in conjunction with the associated parameters, will allow you to choose which dimensions to view from a dropdown in the view as described in Step 5.

    CASE [Parameters].[2nd Dim]
    WHEN 1 THEN [Category]
    WHEN 2 THEN [City]
    WHEN 3 THEN [Country]
    WHEN 4 THEN [Customer ID]
    WHEN 5 THEN [Customer Name]
    WHEN 6 THEN [Order ID]
    WHEN 7 THEN STR( [Postal Code] )
    WHEN 8 THEN  [Product ID]
    WHEN 9 THEN [Product Name]
    WHEN 10 THEN [Region]
    WHEN 11 THEN [Segment]
    WHEN 12 THEN [Ship Mode]
    WHEN 13 THEN [State]
    WHEN 14 THEN [Sub-Category]
    WHEN 15 THEN ""
    END

    CASE [Parameters].[3rd Dim]
    WHEN 1 THEN [Category]
    WHEN 2 THEN [City]
    WHEN 3 THEN [Country]
    WHEN 4 THEN [Customer ID]
    WHEN 5 THEN [Customer Name]
    WHEN 6 THEN [Order ID]
    WHEN 7 THEN STR( [Postal Code] )
    WHEN 8 THEN  [Product ID]
    WHEN 9 THEN [Product Name]
    WHEN 10 THEN [Region]
    WHEN 11 THEN [Segment]
    WHEN 12 THEN [Ship Mode]
    WHEN 13 THEN [State]
    WHEN 14 THEN [Sub-Category]
    WHEN 15 THEN ""
    END

    CASE [Parameters].[4th Dim]
    WHEN 1 THEN [Category]
    WHEN 2 THEN [City]
    WHEN 3 THEN [Country]
    WHEN 4 THEN [Customer ID]
    WHEN 5 THEN [Customer Name]
    WHEN 6 THEN [Order ID]
    WHEN 7 THEN STR( [Postal Code] )
    WHEN 8 THEN  [Product ID]
    WHEN 9 THEN [Product Name]
    WHEN 10 THEN [Region]
    WHEN 11 THEN [Segment]
    WHEN 12 THEN [Ship Mode]
    WHEN 13 THEN [State]
    WHEN 14 THEN [Sub-Category]
    WHEN 15 THEN ""
    END

  • 8. Inspect the following calculated fields, which enable you to choose which LOD calculations to employ and thus to compare and contrast differences and similarities:

    The Case Fixed calculation:

    CASE [Choose Fixed Dims]
    WHEN 1 THEN SUM({FIXED [1st Dim]: SUM([Sales])})
    WHEN 2 THEN SUM({FIXED [2nd Dim]: SUM([Sales])})
    WHEN 3 THEN SUM({FIXED [3rd Dim]: SUM([Sales])})
    WHEN 4 THEN SUM({FIXED [4th Dim]: SUM([Sales])})
    WHEN 5 THEN SUM({FIXED : SUM([Sales])})
    WHEN 6 THEN 0
    END

    The Case Fixed calculation shows that if the user selects 1 in the Choose Fixed Dims parameter (which is being displayed as 1st), the 1st Dim will be fixed—no matter the dashboard setup. That means that SUM(Sales) will be partitioned over the 1st Dim, no matter if it is part of the dashboard.

    The Case Exclude 1 calculation:

    CASE [Choose Excluded Dims 1]
    WHEN 1 THEN SUM({EXCLUDE [1st Dim]: SUM([Sales])})
    WHEN 2 THEN SUM({EXCLUDE [2nd Dim] : SUM([Sales])})
    WHEN 3 THEN SUM({EXCLUDE [3rd Dim] : SUM([Sales])})
    WHEN 4 THEN SUM({EXCLUDE [4th Dim]: SUM([Sales])})
    WHEN 5 THEN 0
    END

    The Case Exclude 1 calculation shows that if the user selects 1 in the Choose Excluded Dims 1 parameter (which will be displayed as 1st), the 1st Dim will be excluded from the calculation in the view. That means that SUM(Sales) won't be partitioned over the 1st Dim, even if it is part of the view.

    The Case Exclude 2 calculation:

    CASE [Choose Excluded Dims 2]
    WHEN 1 THEN SUM({EXCLUDE [1st Dim]: SUM([Sales])})
    WHEN 2 THEN SUM({EXCLUDE [1st Dim],[2nd Dim] : SUM([Sales])})
    WHEN 3 THEN SUM({EXCLUDE [1st Dim],[2nd Dim],[3rd Dim] : SUM([Sales])})
    WHEN 4 THEN SUM({EXCLUDE [1st Dim],[2nd Dim],[3rd Dim], [4th Dim]: SUM([Sales])})
    WHEN 5 THEN SUM({EXCLUDE : SUM([Sales])})
    WHEN 6 THEN 0
    END


    The Case Exclude 2 calculation shows that if the user selects 1 in the Choose Excluded Dims 2 parameter (which will be displayed as 1st), the 1st Dim will be excluded from the calculation in the view. That means that SUM(Sales) won't be partitioned over the 1st Dim, even if it is part of the view.

  • 9. Now, right-click and open the context filter on Product Name for inspection. In the resulting dialog box, click the Wildcard tab and note the settings as shown in the following screenshot. The filter has been set to show only product names that start with S (Match value is not case-sensitive.):
  • 10. After clicking OK, right-click on the filter and note that context filters are denoted in gray color
  • 11. Place the following dimensions on the Rows shelf: 1st Dim, 2nd Dim, 3rd Dim, and 4th Dim.
  • 12. Drag Measure Names onto the Filters shelf and select Sales, Case Fixed, Case Exclude 1, and Case Exclude 2.
  • 13. Add Measure Values to Text and Measure Names to Columns:
  • 14. Display each parameter by right-clicking each one and selecting Show Parameter Control. Order the parameter controls as follows:

By following those previous steps, we are now ready to build various tables in order to compare the different LOD calculations because the parameters will allow us to select different dimensions and the calculated fields that incorporated the FIXED and EXCLUDE functions from Tableau. We will now continue using the playground and explain how LODs change calculated fields.

Understanding FIXED

Now that the playground environment is complete, let's build scenarios to better understand FIXED and EXCLUDE functions. We'll begin with FIXED. The FIXED LOD considers only the dimensions to which it is directed. Thus,

  • when fixed on a dimension, all other (if any) dimensions in the view are being ignored.
  • When the FIXED LOD is used without defining any dimension, the result will be a calculation ignoring all (if any) dimensions in the view.

Let's jump into the exercise and see this for ourselves:

  • 1. Using the worksheet described previously, set the parameters as shown here:

    ==>10==>==>[Region]
    ==>1==>==>[Category]


    explain:

    What we achieve with the different parameters is that we show the SUM(Sales) per Region and each Region per Category based on current view(Rows),

    but we also fixed the SUM(Sales) calculation for the dimension Category in the column Case Fixed.
    2=><=2nd Dim(Category)<==1<==

    for Furniture sub-partition in Category : 10,072 + 14,249 + 4,494 + 18,564= 47,397

  • 2. The Case Fixed column now displays the totals for each Category(sub-partition) and ignores Region because we told the calculation to fix the 2nd Dim ([Category]<==<==1<==parameter controlCategory) and ignore the dimensions in the view itself. The effect of this is visible by comparing the Sales column and the Case Fixed column.
  • 3. Check for yourself and do the math for Furniture:
    10,072 + 14,249 + 4,494 + 18,564 = 47,379
    Even though the Region(it is addressed) is visible in the view, the SUM(Sales) in column Case Fixed ignores the Region and shows the results as if the Category dimension is the only dimension in the view(the remaining dimensions are addressed). We manipulated the granularity of the data. In the Case Fixed column, Region serves for informative purpose and addressing only but does not affect the calculation of SUM(Sales).
  • 4. Now change the Choose Fixed Dims parameter to 1st and note that Case Fixed now displays the totals for each region(sub-partition):
    ==>1==><==[Region]<==10

  • 5. This time we fix the calculation in column Case Fixed to only take the Region into account but ignore the Category(it is addressed). Check for yourself and do the math for Central: 10,072 + 16,340 + 13,995 = 40,406

Change the Choose Fixed Dims parameter to Fixed: Nothing and note that the amount reflects the total SUM(Sales):
==>5==>When the FIXED LOD is used without defining any dimension, the result will be a calculation ignoring all (if any) dimensions(all dimensions will be addressed, the number of partition is 0 or whole table is a partition) in the view.

This time we fixed the calculation to nothing, meaning that we ignore every dimension in the view. Check for yourself and do the math by summing the Sales values; the sum will be 194,776.

As is evident, the FIXED LOD considers only the dimensions to which it is specified. Thus, when fixed on Category, Region is ignored. And, as demonstrated, when fixed on Region, Category is ignored. Lastly, when Choose Fixed Dims is set to Fixed: Nothing, the entire dataset that is only restricted by the context filter on Product Name is displayed.

Next, let's look at a couple of new features introduced with Tableau 2021.1 that pertain to FIXED LODs.

Table-scoped expressions

A quick way to write a FIXED LOD expression when using a whole table as the scope is using code like the following:

{ MAX([Order Date]) }

If you use this calculation on the Superstore dataset, you will achieve the exact same as writing:

{ FIXED: MAX([Order Date]) }

No matter what you show in the view, this field will always retrieve the latest data from the whole table. Cool, right?

Quick LOD calculations

Tableau 2021.1 allows us to create FIXED LODs faster. Simply press Ctrl (or Cmd on macOS) and drag the desired measure on top of a dimension. Now you will see the dimension highlighted in blue (see Region in Figure 7.16). Then drop the measure there and a new measure field (in this case, Sales(Region)) will be created.

Right click on Sales(Region) and then select edit... and note that a FIXED LOD has been created:

https://blog.csdn.net/Linli522362242/article/details/123188872
First of all, SUM, AVG, etc. belong to aggregate function

Some people may wonder why there is an outer AGG ({ FIXED| INCLUDE| EXCLUDE [Dim 1] , [Dim 2] : AGG([Row-Level] ) }) on Text shelf, the reason is that the inner { FIXED| INCLUDE| EXCLUDE [Dim 1] , [Dim 2] : AGG([Row-Level] ) } returns multiple measures

  • (such as the above example, fixed at the Region dimension, but there are multiple dimension values in the Region, so each dimension value of the region will execute the internal { FIXED| INCLUDE| EXCLUDE [Dim 1] , [Dim 2] : AGG([Row-Level] ) } statement, thereby returning multiple measure values),

But, we only need one measure value, so we need to use the outer aggregate function for aggregation to get one measure value.

Of course, if we need dimension values, then the outer AGG function is not needed,

If the dimension values of the dimension in the view corresponds to the measures value obtained by inner { FIXED| INCLUDE| EXCLUDE [Dim 1] , [Dim 2] : AGG([Row-Level] ) }, then the outer AGG function will not be executed

If the number of dimensions in the view is more than the measure value obtained by inner { FIXED| INCLUDE| EXCLUDE [Dim 1] , [Dim 2] : AGG([Row-Level] ) }, then the outer AGG function will not be executed, but the result obtained by the outer AGG function will be duplicated according to the dimensions in the view.https://blog.csdn.net/Linli522362242/article/details/123188872

If you're working with Tableau 2021.1 or higher, you can use this shortcut for FIXED LODs.

The playground we built was not only meant for FIXED but also for EXCLUDE . Let us have a look at EXCLUDE next.

Understanding EXCLUDE

Let us start understanding the EXCLUDE LOD. The EXCLUDE LOD will exclude any dimension to which it is specified. If your view contains Region and Category and you write an EXCLUDE LOD on Category , only Region will be considered in the calculations. The following example will make this clearer—our goal in this exercise is to calculate SUM(Sales) by using fewer dimensions than in the view. We want to exclude visible dimensions only from the calculation but still show the dimension values in the dashboard:

  • 1. Set the parameters as shown in the following screenshot:

    ==>10==>==>[Region]
    ==>1==>==>[Category]
    ==>11==>==>[Segment]
    ==>1==><=[Region]<=<=

  • 2. You can observe the following results:
    Case Exclude 1 displays the total of each Category and Segment and ignores Region(it is addressed). For example, the total of the Segment Consumer within the Category Furniture is $26,738 = 5,444 + 6,941 + 2,052 + 12,301. That total is repeated for each Region. The relevant code that is generating these results is

    SUM({EXCLUDE [Region] : SUM([Sales])})
  • 3. Make the following changes to the parameters:

    ==>3==><==[Segment]<==11<==The associated code for Case Fixed is:

    SUM({FIXED [Segment]: SUM([Sales])})

    ==>1==><=[Region]<==10<== The associated code for Case Exclude 1 is:

    SUM({EXCLUDE [Region] : SUM([Sales])})

    =>2=><==[Region]<==10<==

    <==[Category]<==1<==

    Any LOD calculation can be used with multiple dimensions in a view. In this case, Case Exclude 2 ignores two dimensions: 1st Dim and 2nd Dim, which are associated with Region and Category. The associated code for Case Exclude 2 is, therefore:

    SUM({EXCLUDE [Region],[Category] : SUM([Sales])})

    Case Exclude 2 and Case Fixed now have identical results. This is because excluding the first two dimensions is the same as fixing on the third dimension. Only the third dimension Segment is taken into account in both cases. You can observe the results in the following screenshot:

  • 4. Make the following changes to the parameters:

  • 5. You can observe the results as follows:
  • 6. Note that Case Exclude 2 and Case Fixed no longer have identical results. This is because Ship Mode was introduced and Case Exclude 2 considers Ship Mode whereas Case Fixed does not.
  • 7. Experiment with other settings to further enhance your understanding of the FIXED and EXCLUDE LODs.

EXCLUDE will cause any dimension addressed in the LOD calculation to be removed from the calculation. Multiple dimensions can be part of an EXCLUDE LOD and common use cases include the direct comparison of sales per category in a region versus total sales in a region. Without LODs it would not be possible to show those two sales figures and both dimensions in the same table.

I hope that by following the previous steps you were able to get a better feel for the EXCLUDE LOD. As a quick interlude[ˈɪntərluːd] after those exercises on FIXED and EXCLUDE , let's take a closer look at Tableau's order of operations, as getting the same result for FIXED and EXCLUDE as we have seen in this exercise is not always the case.

Understanding Tableau's order of operations (aka query pipeline)

The previous exercise led us to believe that the same results for FIXED and EXCLUDE can be achieved by fixing the dimensions that are not excluded and vice versa. However, the order in which Tableau executes a FIXED and an EXCLUDE LOD differs and can hence cause unexpected results. In order to avoid this, I will show you what to consider when using either FIXED or EXCLUDE LODs.

Let's have a look at the order of filtering:

  • 1. Set the parameters as follows: 

    ==>3==><==[Segment]<==11<==The associated code for Case Fixed is:

    SUM({FIXED [Segment]: SUM([Sales])})

    =>2=><==[Region]<==10<==

    <==[Category]<==1<==
    The associated code for Case Exclude 2 is

    SUM({EXCLUDE [Region],[Category] : SUM([Sales])})

  • 2. Observe the results:
    Note that, as seen in the previous exercise, Case Exclude 2 and Case Fixed are identical.This is because excluding the first two dimensions is the same as fixing on the third dimension. Only the third dimension Segment is taken into account in both cases.
  • 3. Right-click on the Product Name filter and select Remove from context:==> 
  • 4. Observe the results on the above screenshot
  • 5. Case Exclude 2 and Case Fixed are no longer identical. Case Fixed is no longer impacted by the Product Name filter because the context was removed.

The behavior difference observed between EXCLUDE and FIXED in the preceding exercise reflects the underlying filter order of operation.

  • As shown in Figure 7.26(Remove from context in step 3), Context Filters will impact FIXED , EXCLUDE , and INCLUDE calculations because

    • the Context Filters is being applied first to the dataset,or(That is to say, first, the context filter Product Name filters out products whose product names start with S)
    • then the LOD calculation.==>Case Fixed and Case Exclude 2  (same result)
  • Dimension Filters, however, will only impact EXCLUDE and INCLUDE LODs because
    • the FIXED LOD will be applied to the dataset first, ==>Case Fixed
    • and then the dimension filter,
      (now, the dimension filter Product Name filters out products whose product names start with S)
    • followed by EXCLUDE and INCLUDE LODs. ==>Case Exclude 2 (different with Case Fixed)
    • Dimension Filters:

      When a dimension is used to filter the data in a worksheet, it is called as Dimension filter. It is a non-aggregated filter where a dimension, group, sets and bin can be added. A dimension filter can be applied through the top or bottom conditions, wildcard match and formula.
      ==>Add to Context ==> convert to context filter or

See the following diagram, a schematic representation of the order of operations inTableau: https://help.tableau.com/current/pro/desktop/en-us/order_of_operations.htm

Note: In the order of operations,

  • the latest date filter is global to the workbook,
  • while context filters apply per worksheet.
  • The latest date is determined just after the workbook opens for first use, after data source filters, but before context filters.
  • At that point the date is set, and the latest date preset is used as a dimension filter.

The name of filter types are sorted based on the order of execution in Tableau. https://www.guru99.com/filter-data-tableau.html#:~:text=can%20be%20executed.-,Dimension%20Filters%3A,conditions%2C%20wildcard%20match%20and%20formula.

  1. Extract Filters

    Extract filters are used to filter the extracted data from data source. This filter is utilized only if the user extracts the data from data source.

    Once the text file is connected to Tableau, you can see the live and extract option in the top right corner of data source tab.
    Live Connection directly connects to a data source.
    Extract connection extracts the data from data source and creates a local copy in Tableau repository.

  2. Data Source Filters
         A data source filter is used to filter the data in data source level. It can restrict the records present in the data set. This filter is similar to extract filter on securing the data. But data source filter and extract filter is not linked to each other. Data source filter works on both live and extracts connection.
  3. Context Filters
         A Context filter is an independent filter that can create a separate dataset out of the original data set and compute the selections made in the worksheet. One or more categorical filter that separates the dataset into major parts can be used as a context filter. All other filters used in the worksheet works based on the selection of context filter.

    1. the Context Filters is being applied first to the dataset,
    2. then the LOD calculation
  4. Dimension Filters
         When a dimension is used to filter the data in a worksheet, it is called as Dimension filter. It is a non-aggregated filter where a dimension, group, sets and bin can be added. A dimension filter can be applied through the top or bottom conditions, wildcard match and formula.

    1. the Context Filters(if not exists)
    2. the FIXED LOD will be applied to the dataset first
    3. and then the dimension filter,
    4. followed by EXCLUDE and INCLUDE LODs
  5. Measure Filters
         A measure filter can filter the data based on the values present in a measure. The aggregated measure values can be used in measure filter to modify the data.

We just saw that when using a context filter, EXCLUDE and FIXED LODs can result in the same numbers, whereas a dimension filter will cause the result to differ. This is happening because Tableau executes the different requests after one another. As can be seen in the preceding diagram, the order of operation goes:

  • 1. Context filters
  • 2. FIXED LOD
  • 3. Dimension filters
  • 4. INCLUDE and EXCLUDE LODs

This is important for you to know in order to choose the correct filter or LOD for your purpose.

Next, we will use a new playground, this time, to show how INCLUDE LODs work.

Playground II: INCLUDE

The second playground we will build will be for the purpose of exploring INCLUDE . Like in Playground I: FIXED and EXCLUDE, we'll start with setting up the workbook for effective exploration. If you do not have ready access to the workbook, you should be able to construct a similar one by referencing the following information.

Setting up the workbook

In the following, we will set up a worksheet with which we can practice the INCLUDE LOD calculations:

  • 1. Open the workbook associated with this chapter and navigate to the Exploring Include worksheet
  • 2. The parameters and calculated fields named 1st Dim, 2nd Dim, 3rd Dim, and 4th Dim created in the previous exercises are also utilized for this worksheet
  • 3. Right-click on the 1st Dim parameter and choose Duplicate
  • 4. Rename the duplicate Choose Included Dims
  • 5. Create a new calculated field named Case Include with the following code:
    CASE [Choose Included Dims]WHEN 1 THEN AVG({INCLUDE [Category]: SUM([Sales])})WHEN 2 THEN AVG({INCLUDE [City]: SUM([Sales])})WHEN 3 THEN AVG({INCLUDE [Country]: SUM([Sales])})WHEN 4 THEN AVG({INCLUDE [Customer ID]: SUM([Sales])})WHEN 5 THEN AVG({INCLUDE [Customer Name]: SUM([Sales])})WHEN 6 THEN AVG({INCLUDE [Order ID]: SUM([Sales])})WHEN 7 THEN AVG({INCLUDE [Postal Code]: SUM([Sales])})WHEN 8 THEN AVG({INCLUDE [Product ID]: SUM([Sales])})WHEN 9 THEN AVG({INCLUDE [Product Name]: SUM([Sales])})WHEN 10 THEN AVG({INCLUDE [Region]: SUM([Sales])})WHEN 11 THEN AVG({INCLUDE [Segment]: SUM([Sales])})WHEN 12 THEN AVG({INCLUDE [Ship Mode]: SUM([Sales])})WHEN 13 THEN AVG({INCLUDE [State]: SUM([Sales])})WHEN 14 THEN AVG({INCLUDE [Sub-Category]: SUM([Sales])})WHEN 15 THEN 0
    END

  • 6. Place the following measures and dimensions in their respective shelves:
  • 7. Display the necessary parameters by right-clicking each one and selecting Show Parameter Control

After you have finished the initial setup, we can start to look into, last but not least, the INCLUDE LOD.

Understanding INCLUDE

Now that the playground environment is complete, let's build scenarios to better understand INCLUDE. By now you can probably imagine that if the FIXED and EXCLUDE LODs remove dimensions from a calculation, INCLUDE adds dimensions. Correct! It might happen that you want to include one or more dimensions in a calculation even though the view doesn't show them. The next example will make use of this functionality in order to show an average per sub-category without showing the sub-category. One would want to do so because the sub-category has so many additional values that the dashboard will be harder to read, and it will take longer to draw quick conclusions. Nevertheless, it is of interest to know the average per sub-category because the number of sub-categories might differ per region and other dimensions, and thus including it will give insights into the real average sales.

Let's see it in action:

  • 1. Set the parameters on the right-hand side as shown here 
    ==>10==>
  • 2. Add two reference lines by clicking on Analytics panel and edit them using the following settings:
  • 3. If the Reference Lines are overlapping each other, edit the formatting and set Alignment to Top. To access the formatting, click on the Reference Line in the view:
                 
  • 4. Look at the following screenshot for the result. Note that both Reference Lines are equal: 2,297,201/(4*3*3)=63,811 (the Region field in the Calculated field Case Include is also in the View )
  • 5. Now, set the parameters as shown here:==>
  • 6. In Tableau Desktop, you should now see the following. As before, both Reference Lines are equal:   2,297,201/(4*3*4*3)=16,064 (the Region field in the Calculated field Case Include is also in the View )
  • 7. Change the Choose Included Dims parameter to Category, Ship Mode, and Segment.
  • 8. Note that the Reference Lines equal one another for each of these settings. This is because Choose Included Dims is only introducing dimensions already represented in the view.
  • 9. Change the Choose Included Dims parameter to Sub-Category:

The Include Dim Avg reference line now includes Sub-Category in the average and therefore differs from the Overall Avg reference line(without including Sub-Category). The average is smaller because the total Sales amount is being divided over more points than are visible in the view. Adding Sub-Category to the LOD leads to more rows, which leads to a smaller average per row. Furthermore, note that the Sub-Category dimension is not used in the view. LOD calculations do not require a calculation to reside in the view.

To summarize, the INCLUDE LOD can manipulate a visualization in a way that partitions can be added that are not used in the view itself. Also, the naming convention for all three LODs will be your best mnemonic in understanding them:

  • FIXED to fix the fields used,
  • INCLUDE to add "missing" fields,
  • and EXCLUDE to remove unwanted fields from the calculations that are already present.

To get more hands-on training, we will continue with a few practical applications.

Building practical applications with LODs

The first portion of this chapter was designed to demonstrate how LOD calculations work. The remainder will be dedicated to practical applications. Specifically, we will consider three typical challenges that previously were solved using other Tableau capabilities, such as table calculations and data blending.

This exercise will look at a problem that occurs when mixing a table calculation that calculates the percentage of the total with a dimension filter. We will consider the problem, a solution using a LOD calculation, and finish with a commentary[ˈkɑːmənteri]评论 section on the germane[dʒɜːrˈmeɪn]有密切关系的 points of the solution.

Using the LOD calculation FIXED

First, we will start off with a common problem many Tableau users come across when working with the FIXED LOD. The following steps will guide you through the exercise:

  • 1. Open the workbook associated with this chapter and navigate to the worksheet entitled The Problem.
  • 2. Select the 2012_World_Pop dataset.
  • 3. Create a calculated field named Percent of Total with the following code:
    SUM([Population])/TOTAL( SUM([Population]) )

  • 4. Right-click on Percent of Total and select Default Properties | Number Format | Percentage.
  • 5. Place Country on the Columns shelf, Measure Names on the Rows shelf, and Measure Values on the Text shelf.
  • 6. Remove Number of Records from the Measure Values shelf.
  • 7. Right-click on Percent of Total and set it to Compute Using | Country (it is addressed).
  • 8. Create a filter on Country such that only Afghanistan displays:

Afghanistan displays the percentage of the total as 100%. Obviously, this does not represent Afghanistan's percentage of the total population of the world. Let's look into a possible solution—to solve the issue with a LOD, follow along with the exercise steps:

  • 1. Duplicate the worksheet entitled The Problem and rename it Solution LOD.
  • 2. Create a calculated field named Percent of Total LOD with the following code:
    SUM([Population])/SUM( { FIXED : SUM([Population]) } )

  • 3. Place Percent of Total LOD on the Measure Values shelf and note that the displayed percentage equals 0.43%. If 0 displays, change the number formatting to percentage:
    • Context Filters
    • Fixed LOD ==> Percent of Total LOD
    • Dimension Filters ==> Percent of Total
    • INCLUDE and EXCLUDE LODs

  • 4. Remove the Percent of Total table calculation that was previously created from the Measure Values shelf:

As you can see, problem solved! To better understand what is happening in the background, let's look at a query that Tableau generates for the worksheet entitled The Problem. Generated queries can be viewed by clicking Help | Settings and Performance | Start Performance Recording. (See Chapter 11, Visualization Best Practices and Dashboard Design, for additional information regarding viewing Tableau's generated queries.)

The SQL statement is as follows:

SELECT['2012_World_Pop$'].[Country] AS [Country],SUM(['2012_World_Pop$'].[Population]) AS [sum:Population:ok]
FROM[dbo].['2012_World_Pop$'] ['2012_World_Pop$']
WHERE(['2012_World_Pop$'].[Country] = 'Afghanistan')
GROUP BY['2012_World_Pop$'].[Country]

==>

==>==>

==>
==>

Note that the WHERE clause in the query is limiting the returned dataset to only those rows that have Afghanistan as Country. This WHERE clause was generated as a result of placing Country on the Filters shelf. By limiting the returned data, the processing requirements are shifted from Tableau to the underlying data source engine. In other words, the data source engine does the work of executing the query, and Tableau thus works with a smaller dataset. The reasoning behind this design is that data source engines are specifically engineered to efficiently query large datasets and also typically have underlying hardware to support such activities. Furthermore, limiting the rows of data returned to Tableau can reduce inefficiencies due to latency.

Inefficiencies are further reduced because Tableau works from cache whenever possible. Often, a user can perform various operations without generating a call to the underlying data source. However, in the preceding case, if a user were to select a different Country from the filter, Tableau would generate a new query to the data source. For example, if a user interacts with the filter and deselects Afghanistan and selects Albania, a new query with a corresponding WHERE clause is generated. Although the logic of Tableau's reliance on the data source engine is demonstrable, the problem proposed in the preceding example still remains. What can a Tableau author do to calculate the percent of the whole regardless of filtering?

A solution is to create a table calculation that can also be used as a filter. The difference is that, unlike in the worksheet The Problem, the query generated by Tableau to the data source returns the entire dataset. When a table calculation is used in a filter, the filtering does not take place until the underlying data is returned. In other words, Tableau performs the filtering. This preserves a percent of the total percentages regardless of which country population totals the user chooses to view.

But, a potential issue with table calculations is that the returned dataset may be quite large, which may cause performance challenges. Latency may be experienced due to increased time required to return a large dataset and Tableau may perform more slowly because of additional processing responsibilities to filter the dataset.

Our proposed solution, an LOD calculation, can address these challenges. Let's take a look at the SQL queries created by the Percent of Total LOD calculated field in the Solution LOD worksheet:

SELECT[t0].[Country] AS [Country],[t1].[ measure 0] AS [TEMP(Calculation_418553293854285824)(2417030171)(0)],[t0].[TEMP(Calculation_418553293854285824)(616435453)(0)] AS [TEMP(Calculation_418553293854285824)(616435453)(0)]FROM( SELECT ['2012_World_Pop$'].[Country] AS [Country], SUM( ['2012_World_Pop$'].[Population]) AS [TEMP(Calculation_418553293854285824)(616435453)(0)]FROM[dbo].['2012_World_Pop$'] ['2012_World_Pop$']WHERE(['2012_World_Pop$'].[Country]= 'Afghanistan')GROUP BY['2012_World_Pop$'].[Country]) [t0]CROSS JOIN
( SELECTSUM(['2012_World_Pop$'].[Population]) AS [ measure 0]FROM[dbo].['2012_World_Pop$'] ['2012_World_Pop$']GROUP BY ()
) [t1]

==>

==>

 https://www.w3resource.com/sql/joins/cross-join.php

Note the term CROSS JOIN ; the LOD calculation generates a query that instructs the underlying data source engine to return data in such a way as to allow Tableau to divide the population values of one or more countries by the world population total, thus returning the correct percentage of the total. 

Using the LOD calculation INCLUDE

Next, we will practice the INCLUDE LOD. In this exercise, we will create a worksheet that displays the following:

  • Total sales per region
  • • The average of total sales across all regions
  • • The average of total sales across all states in each region

Using a LOD calculation to display these values is pretty straightforward. Let's explore. Follow along with the exercise steps:

  • 1. Select the Practical Include worksheet.
  • 2. Select the Superstore dataset.
  • 3. Create a calculated field named Per State INCLUDE with the following code:
    { INCLUDE [State]:SUM([Sales]) }

  • 4. Drag Region to the Columns shelf, SUM(Sales) to the Rows shelf, and Per State INCLUDE to the Details shelf. Be sure to change Per State INCLUDE to an average aggregation(Measure|Average).
  • 5. Add two Reference Lines by right-clicking on the Sales axis and selecting Add Reference Line. Use the following settings:


                                                                                                           
  • 6. Complete the worksheet by formatting it as desired:

As you can see, thanks to the LOD we can display a line chart per Region, as well as one for the whole dataset. This is possible because we included the State dimension(it is partitioned) in our Per State INCLUDE calculation. Using this calculated field to create a reference line allows Tableau to show not only the average per (visible) region but also the average per state (invisible) per region.

Using the LOD calculation EXCLUDE

In this exercise, we will create a worksheet using the Superstore dataset, which will calculate the percentage of sales generated by each city in a region.

Follow along with the exercise steps:

  • 1. Select the Practical Exclude worksheet.
  • 2. Select the Superstore dataset.
  • 3. Create the following calculated fields: 
    Region Values

    { EXCLUDE [City],[State]: ZN( SUM([Sales]) ) }


    % Per Region LOD

    SUM([Sales]) / SUM([Region Values])

  • 4. Place Region and City on the Rows shelf.
  • 5. Place Measure Names on the Columns shelf and Measure Values on the Text shelf.
  • 6. Remove all instances of measures from the Measure Values shelf except
    • Sales,
    • Region Values,
    • and % Per Region LOD.
  • 7. In order for % Per Region LOD to display as a percentage, the number formatting must be adjusted. Simply right-click on the calculation in the Data pane and select Default Properties | Number Format | Percentage:
  • 8. Place an instance of AGG(% Per Region LOD) on the Filter shelf and adjust to display at least 0.1 (or, 10%):
  • 9. Observe the current view, with Region and City on the Rows shelf:
  • 10. Now, place State on the Rows shelf between Region and City. Note that South and Jacksonville disappears:
         This is happening because Jacksonville exists in two states of the South region, in Florida as well as in North Carolina;
    Furthermore,
     the Filter AGG(% Per Region LOD) requirements  > 10%:

Our Region Values calculation excluded City and State and so the % Per Region LOD will take into account the SUM(Sales) for whatever is visible in the view, divided by the Region Values. With Region and City in the view only, the SUM(Sales) for Jacksonville is 44,713 (see Figure 7.48). That number divided by the Region Values of 391,722 (see Figure 7.50) is > 10%.

But then we added State to the view, changing the SUM(Sales) to 39,133 for Jacksonville in Florida and 5,580 for Jacksonville in North Carolina (see Figure 7.50). Neither one of them when divided by 391,722 for the Region Values is above 10% and will therefore drop from the view due to our filter.

LOD calculations are one of the more advanced topics when using Tableau but they are very powerful and worth spending the time to understand. For more practical examples I would recommend you checking the following website: https://www.tableau.com/about/blog/LOD-expressions. I remember that, when I first started using Tableau, I didn't think that I would ever want to show data based on dimensions that are not in my view, or that I would want to exclude dimensions. But I needed them so many times. I went back to the documentation on LODs more often than you can imagine, and I can only encourage you to do the same; the more you read about LODs, the easier it will be to grasp the concept and use them naturally. The added flexibility LODs bring to your dashboard is incredible.

Summary

We began this chapter by exploring why LOD calculations are so impactful and why their inclusion in Tableau was so lauded. Next, we built two playgrounds to explore how the three LOD calculations— FIXED, EXCLUDE, and INCLUDE —work. Tableau's default is to base calculations on the dimensions visible in the view. For example, if you have states in your view, the sales amount will be presented by state. If you are adding cities, the sales amount will be adjusted by state, by city. But, if you want to manipulate this default logic, you can use LOD calculations. They allow you to calculate measures based on any dimension, no matter whether that dimension is represented in the view or not. We also saw that FIXED LODs are higher in the order of operations in Tableau than EXCLUDE and INCLUDE LODs. This is important to  remember in order to use the correct LOD and/or filter in your dashboard.

In the next chapter, we'll turn our attention to the visual side of Tableau and explore different chart types and less common but very useful visualizations.

mtb7_参数控制要显示的维度Level of Detail Calculation_Context Filter > Fixed > Dimension > Include Exclude VizQ相关推荐

  1. 润乾报表主子报表通过参数控制子报表显示

     客户需求: 通过参数控制1张汇总表中展现哪个或者哪几个子报表 制作报表样式如下图: 其中第2行  隐藏行表达式为if(@arg1==1,true,false)  插入的子报表是aa00.raq ...

  2. vc可以实现对话框里显示html文档内容,也可以显示word内容吗,VC6中使用CHtmlView在对话框控制中显示HTML文档...

    VC6中使用CHtmlView在对话框控制中显示HTML文档 2008-02-23 05:29:58来源:互联网 阅读 () 在Visual Studio 6.0中出现了一个新类CHtmlView,利 ...

  3. 利用单片机控制74HC595显示图案

    利用单片机控制74HC595显示图案(单片机型号STC89C52) 此文将介绍如何用74HC595自定义显示图案,需要一定的单片机学习基础,话不多说,上代码 #include "reg51. ...

  4. plt.imshow()中cmap参数控制颜色展示

    plt.imshow()中cmap参数控制颜色展示 以A = [[0,1,2],[3,4,5],[6,7,8]]为例进行展示 plt.imshow(A, cmap="xxx")其中 ...

  5. SwiftUI UISearchbar 如何编程控制cancle显示

    实战需求 SwiftUI UISearchbar 如何编程控制cancle显示 实战代码 searchController.isActive = false 推荐 基础文章推荐 <SwiftUI ...

  6. UE4-(蓝图)第十五课平视显示器(程序设置HUD显示内容并控制HUD显示隐藏)

    实现从外部设置Text显示文本,要用到绑定功能. 一.从外部设置Text显示文本 1.在HUDWidget1的控件蓝图编辑器中,选中放置的Text,在细节中找到Content下的Text属性,右侧显示 ...

  7. V4L2+Qt5实现摄像头视频采集以及参数控制

    这一段时间在做摄像头控制方面的工作,需要在Linux下实现对摄像头名称和分辨率的获取,同时对亮度.对比度.曝光值等参数进行控制,同时还需要对获取的帧画面进行处理.目前除了图像处理方面,简单的使用V4l ...

  8. STM32控制TFTLCD显示

    一.用STM32控制TFTLCD显示的编程方法,在编程驱动TFTLCD液晶显示器之前,我们先熟悉以下概念: 1.色彩深度,这是一个与TFTLCD显存对应的概念:所谓色彩深度就是每个像素点需要多少位的R ...

  9. 通过style来控制隔行显示不同颜色 .

    通过style来控制隔行显示不同颜色 .  <style> tr{ bgcolor:expression(this.bgColor=((this.rowIndex)%2==0 )? 'gr ...

最新文章

  1. hashMap传入参数,table长度为多少
  2. STM32 进阶教程 11 - RAM中运行程序
  3. 深度探索C++ 对象模型(7)-Data member的布局(多重继承)
  4. python使用环境_使用python之环境管理
  5. Linux之centos镜像
  6. jquery find 找到frame select_简述jQuery
  7. 搞懂 Java HashMap 源码
  8. 80后程序员必须知道的编程语言和它们的创造者
  9. 搭建Nginx+PHP环境
  10. 软件测试工程师 Linux 十大场景命令使用
  11. 数据挖掘之apriori算法(python实现详细注释)
  12. Ubuntu Linux 15.04安装 nginx + passenger
  13. python学习之编写学员管理系统
  14. Android开发常见问题及解决方法
  15. 手把手教你用WOS数据库解决英文文献
  16. 计算机默认应用程序怎么取消,如何取消默认打开的QQ浏览器
  17. apple id是什么意思
  18. 生鲜电商运营框架的对比和分析
  19. Java装机必备软件下载JDKGITMavenNodeJS
  20. 通过Gearman实现MySQL到Redis的数据复制

热门文章

  1. 三八妇女节送什么礼物给女生?女神节礼物推荐
  2. 注册表修改鼠标右键中新建菜单性
  3. JavaScript 原型链运行原理
  4. 大蟒蛇python头像_【Python图像】给你的头像+1
  5. Android设计模式--模板方法模式
  6. NS3 入门环境搭建
  7. Stata16安装包下载及安装教程
  8. xcode里的描述文件 位置
  9. DNF虚拟机防检测过TP NP 无机器码 不蓝屏 极限优化快速
  10. HTML summary