Tableau’s mission is to help people see and understand data. Our features are carefully designed to help people transform data into meaning. One area of focus is calculations. The easier it is to express ideas in a calculation language, the more meaning people can generate. The introduction of Level of Detail (LOD) Expressions in Tableau 9.0 was a breakthrough in this regard. These LOD expressions let people express powerful concepts using simple statements.

What Are LOD Expressions?

LOD Expressions provide a way to easily compute aggregations that are not at the level of detail of the visualization. You can then integrate those values within visualizations in arbitrary ways. That may sound abstruse, so this post will illustrate the concept through a series of common questions. Near the end, we will dive into some more advanced analytic examples. The whitepaper on Level of Detail Expressions provides a more general overview. For details on syntax and usage, see Level of Detail Expressions in the Tableau Desktop online help section.

Each of the following 15 workbooks contains customized data sources and can be downloaded for further details. If you do not have a copy of Tableau Desktop, you can get a free 14-day trial here. We recommend that you use these customized data sources if you choose to follow the instructions and re-create the views.

1. Customer order frequency

Finding the number of orders each customer has made is relatively easy, but what if we wanted to know the number of customers who made one order, two orders, three orders, and so forth? To build this view, we must break up the number of customers by the number of orders made. This is a simple question, but breaking out a measure by another measure would be difficult without LOD Expressions.

Consider the sales database of a superstore that has multiple items per order. The distinct count of orders by customer gives the number of orders each customer made. A simple LOD expression can turn the number of orders into a dimension that breaks out the number of customers.

2. Cohort analysis

Do longer tenured customers make a larger contribution to sales? The view below groups customers by the year of their first purchase to compare sales contributions annually across cohorts. The minimum order date per customer will give the first purchase date. However, since the data in the view is not displayed by customer, we must use an LOD Expression to fix the minimum order date per customer.

3. Daily profit KPI

We can certainly view profit trends over time, but what if we measure our success by the total profit per business day? We would probably want to know the number of profitable days achieved each month or year, especially if we were curious about seasonal effects. The following view shows how LOD Expressions allow us to easily create bins on aggregated data such as profit per day, while the underlying data is recorded at a transactional level.

4. Percent of total

What is each country’s revenue contribution to global sales? If we color by the contribution percentage, we immediately see that the US has the highest contribution to the global sales revenue. However, we may want to focus on a market like the EU that, in absolute terms, has a small contribution. Without LOD Expressions, filtering on a market would cause the percent of total to recalculate, displaying each country’s contribution to its market. With a simple LOD Expression, we can filter on a market, and still measure the global contribution.

5. New customer acquisition

What is the daily trend of total customer acquisition by market? Finding the trend in this data will help us understand how well the regional marketing and sales organizations are doing at generating new business. The steeper the line, the better the acquisition trend. As a line flattens out, some action must be taken to increase lead flow.

An LOD Expression ensures that repeat customers are not miscounted as new customers, as data must be evaluated at the customer level even though it is displayed visually by market and day.

6. Comparative sales analysis

It’s relatively straightforward to find the difference from average, but what if you wanted to find the difference from a selected category? First, you must isolate the sales of the selected category. Then an EXCLUDE Expression is needed to repeat that value across all other categories. It is then easy to take the difference of each category’s sales from the rest.

7. Average of top deals by sales rep

What is the largest deal that each sales rep has closed? And then considering these top deals by sales rep, what is the average by country? LOD Expressions allow us to look down to the sales rep level of detail even though the data is displayed visually at the country level. In the view below, the average top deal size by sales rep is higher in countries colored blue and lower in countries colored orange. We can use this information to guide drill-down analysis from country to sales rep.

8. Actual vs. target

In this visualization, we are displaying the difference in actual profit compared to target profit per state for a chain of coffee houses. In the top view, we can clearly see which states have exceeded the target and which states missed the target. However, when aggregating up this way, we can miss important nuances. Some states are above target because every product sold in that state is above target. Others are above target because a single product exceeded its target by enough to make up for all of the other products that missed their target. We can use an LOD Expression to identify the percentage of products sold within a state that are above target.

9. Value on the last day of a period

Data that represent the status on a particular day such as inventory numbers, headcount of employees, or daily close value of a stock need be treated differently than metrics that can be aggregated such as sales or profit. In these cases, you may want to display the value on the last calendar day of a month. Furthermore, we would expect that drilling down from month to week would update to display the value on the last day of the week. In the example below, we have stock data for multiple tickers on a daily level. The view compares the average daily close value to the close value on the last day of the period. Using a simple LOD Expression, we can look down to the daily level, even if the data is displayed visually at a higher level.

The following 6 examples illustrate how level of detail expressions can be applied to more advanced scenarios, as well as use cases that draw on the broader feature set of tableau. For further examples of more basic scenarios, watch the On Demand Training Videos on LOD expressions.

10. Return purchase by cohort

Acquiring new customers can be expensive, so we want to ensure that existing customers are making repeat purchases. How many customers take one, two, three, N quarters to make a repeat purchase? How many have never made a repeat purchase? What does this behavior look like broken out by quarterly cohorts? We can use a FIXED Expression to find the first and second purchase dates per customer, and derive the number of quarters to make a repeat purchase from this.

11. Percent difference from average across a range

Example 6 shows how to make a comparison to a single selected item, but what if you wanted to make a comparison across a range of values? For example you may want to compare the daily close value of a stock to the average daily close value before a major event occurred that affected the industry in question.

12. Relative period filtering

A common metric for analyzing performance is year-to-date and month-to-date comparisons relative to the previous year. We can do this easily by filtering relative to today, but what happens if the data is refreshed on a weekly basis? Suppose your last refresh occurred on March 1, but the current day is March 7. A month-to-date comparison would show March 1 through March 7 of the previous year versus March 1 of the current year. This could cause significant alarm, where none is needed! A simple LOD Expression allows us to find the maximum date in the dataset.

13. User login frequency

How many users log in to a website or application once a month, once every two months, once every three months, and so forth? What is the average login rate? How does the distribution skew around this average? The granularity of the data is log in date per user ID. In other words, there is one row for every day that a user logged in. Building this view requires slicing the number of customers by the login rate, meaning that we must slice a measure by a measure. We saw in example 1 how LOD Expressions make this type of analysis easy.

14. Proportional brushing

The most fundamental question in any analysis is: “Compared to what?” Sometimes when filtering, we would like to compare the selection to the total amount, as opposed to simply filtering down to the selection. This technique is known as proportional brushing.

15. Annual purchase frequency by customer cohort

Are more tenured customers more loyal, where tenure is measured by the year of customer acquisition and loyalty is measured by annual purchase frequency?

We know from example 1 how many customers purchase exactly one time, exactly two times, and so forth. However rarely will a marketer want to identify all customers who purchased exactly five times. Instead, it may be more useful to know how many customers purchased at least five times.

Additionally we know from example 2 that most customers are acquired in 2011 and fewest customers are acquired in 2014. Looking at the absolute number of customers will only reveal this same trend again. Therefore, it may be more interesting to see the percent of total customers per cohort as a measure of loyalty.

So to rephrase the initial question more concretely, what percentage of customers in each cohort purchased at least one, two, three, N times in a year?

This example combines a variation of the number of orders LOD Expression from example 1, the cohort expression from example 2, and a variation of the percent of total expression in example 4.

Comments

I am new to LoD calcs and am interested in performing the Customer Order Frequency, but over a specific period of time, with a specific product. Any suggestions on how to perform this analysis, with the use of filters? I would use the include LoD calc, but doing so prevents me from moving the calculation from measure to dimension.

Thank you!

Matt

This made my love of Tableau complete. Thank you for making our analysis easier each day.

There is no link to download "proportional brushing" How can I downloaded it?
Thanks

This is very beautiful post its equip me as a Tableau developer. More of it please.

Thanks

Hi Bethany
Its been a long time since anyone commented on THE most useful posts there is on LOD's, so thought I'd throw you a line to see if you still respond.....on 5, is there a reason why you plot Day(order date) and then filter on the calculated field for New customers only, instead of just using Day(First Order Date) without the calculated field in the filter? It seems logical to me and seems to return the same results.
All the best
Steve A

Thank you for post, very usefull

i am tableau beginner its very full notes and thank full to Tableau Community(library)

I don't see a way to download the workbooks. Are they still available?

Hi Jess,

You can download the workbooks by clicking the "Download" icon on the bottom right corner of each viz. Then click "Tableau Workbook" and it should automatically download to your device.

Best,
Hannah, Social Media Team at Tableau

There is a "download" button at the bottom of every viz.

I have a few questions about the first calculation: 1. Customer Order Frequency.

I created the calculation on my dataset, but it was not constrained by time.

Questions:

1. Can I now add a time bound to this viz so that it calculates the number orders by a customer in a fixed monthly period?

To do this I have used the [Creation Date] of the [Order ID] available in my data. What is the right way to use [Creation Date] to constrain my data. Use it:
i) as a filter OR
ii) as a row or column dimension?

Q2: I now want to look at the number of "Customers with N orders" as a percentage of the data set (for each time period).

a) I simply do a Quick Table Calculation->Percentage of Total

Here is the real problem.

- The Monthly % of "Customers with 1 order" is almost consistent over 12 months, plus minus few percentage points.

- When I change the viz to Yearly % of "Customers with 1 order", the resulting percentage is much lower than the average I would expect of the monthly numbers!

I suspect it is some novice mistake I am making but any resources or help would be good!

Thanks

Perfect!!!

Is this post broken? The workbook links and the images are missing.

Amazing.. thank you team.. Good job!! Very useful for me to learn . it gives me many ideas to analyse the Data. Thank you so much

Where can I find the related data sources for downloading ?

Hi Team,
Great post. But can somebody help me with Dataset used for each LOD problem.?


Subscribe to our blog

Don't get left out(lier)

Join the largest data conference
Las Vegas | Nov 12–15, 2019