Filling in Dates, but not for dates but for integer numbers series in x axis.

Some day someone asked how do I go from here:

f9551bd8-e7df-499f-a5f0-4699c4b61e40.png
Missing cases in an integer numbers variable in X-axis are not plotted. Only existing x cases have correspondent y values, but all are placed one after another.

To something like this:

39722f51-abd3-4d5f-abc5-7d375d41a2e9.png
The independent variable is regular spaced and missing values are plotted as having y=0.

I know, the very fast answer: go talk to your BD admin and ask him to build such x-axis independent variable.

But what if I feel brave enough to try it directly working on Looker?

Well, here are the steps I took to achieve it:

1.- First, grabbing any enough long in rows DB field, like ID for example, through ROW_NUMBER() function, I could set up a derived table that contains a regular paced variable with a proper alias.

derived_table: {

 sql: select row_number() over(order by Id) as consecutivos from                public.products;;

    }
 

2.- If the field with jumps is a Dimension, convert it to a Measure. Using this awesome trick 

https://community.looker.com/technical-tips-tricks-1021/how-do-i-visualize-a-dimension-as-a-measure-...

3.- Merge accordingly, taking as primary query the regular paced x-axis independent variable that was made before. And match it with the dimension with jumps. So it will generate Null values where it doesn’t find a match. And include the correspondent measure. At the end, I got something like this:

541400ae-f957-4688-8f8e-5ed4cc8d4e41.png

Anyway. This is as far as I got. I hope you may find it useful.

Blessings.

Juan P

1 0 200
0 REPLIES 0
Top Labels in this Space
Top Solution Authors