The SQL behind Tableau INCLUDE LOD

mustafac
4 min readDec 30, 2022

--

At this post, I will continue with INCLUDE LOD. The dataset info and testing conditions are explained at an other post.
Explanation of data : Link
Fixed LOD : Link

For this post we use LOD below.

INCL STATE ORDERS
{INCLUDE [State] : COUNTD( [Order ID] ) }

  1. Country, State, City

Below we can see that, when we have a deeper level(City) in view, we can break until that level. Include does not effect calculation here.

Tableau SQL associated with this view is as below. It is a “COUNT DISTINCT” by our 3 fields.(Country,State,City)

With Filter,Tableau SQL does not change much, only where added.(This was not the case in FIXED LOD)

2) Country Category

At above query we see the inner query does not use State in select but in group by. At below we can see that when we execute this query, altough State is not in select, final result breaking is by select.

3) State City
For this case, since State is at view, query is very simple.

4) Country City
We have a hierarchy as Country -> State -> City. Here we select Country and City. State is included in subquery , as in the case of our 2nd example “Country, Category”.

5) Country
When only we have country, we again use State only for group by.

Associated Pandas SQL:

6) City
Same logic as in Country.

7)Only LOD
When we only use our INCLUDE LOD in view, associated query in aggregation(SUM) over a “count distinct group by”.

8) Category

9) Category State
At 8 above, we needed an inner query because State was not in view, when State in view, query gets simplified, no more need for an inner query.

10)Category State with Filter

When filter added, query does not get more complicated, it is just a where added. This was not the case for FIXED LOD.

Here I showed enough sample to understand the SQL behin Tableau.
* When field is already at view, seems nothing changes.(As expected)
* When field is not at view, it is used, as breaking in group by, without putting into select.

--

--

mustafac
mustafac

Written by mustafac

Data Scientist & Machine Learning

No responses yet