How To Think Tableau Level of Detail Expressions as Writing SQL Group By

Three examples to demonstrate how I approach different business problems

thejasmine
Analytics Vidhya
3 min readFeb 17, 2021

--

Photo by Coffee Geek on Unsplash

Level of Detail Expression is an important concept for Tableau calculation field.

FIXED level of detail expressions compute a value using the specified dimensions, without reference to the dimensions in the view. FIXED Level of Detail Expressions

When learning how to write LOD, I struggled a lot. I don’t know which column I need to put after fixed clause. One day, I came up with an idea. LOD is just like SQL’s group by function.

I decided to test it out, and I would like to share how I think LOD in SQL way, and it does help me to write LOD calculation in Tableau quicker.

For this demo, I would like to use the Tableau superstore dataset, and I have imported the file into my local SQL database.

1. Region Sales

When writing the SQL query, I used “region” as group by column. As for tableau, the region column is used as a fixed clause.

SQL

Tableau

For the tableau table, the Region Sales column used LOD, and the Sales use the table view

2. Customer Earliest Order Date Cohort

For this problem, please take a loot at sub-query. “Customer ID” are grouped by each customer id ‘s earliest order year. As for tableau, I used customer id as fixed clause.

SQL

Tableau

In 2017, there were 595 customers who placed their first order. The number of new customers decreases dramatically year over year.

3. Region and category comparison table

SQL

Tableau

As for category average sales, I used table view to filter the result.

Main takeaway

Think of SQL, when you want to put a column as a group by column, you put the column as the Tableau fixed clause.

It is my way to think of Level of Detail Expression, and I found it is beneficial for me when I am stuck. I hope you will find this helpful:)

--

--