Knowledge Drop

How do I calculate the number of digits in a value using table calcs?

Last tested: May 18, 2020

We can do this using the power of logarithms! Looker's log() function uses log base 10, so it will return an integer for each value that is a power of 10 - eg. log(1) = 0, log(10) = 1, and so on. So, for integer values of log(x), we can return "log(x) + 1". For all other values, we can round up using the ceiling() function.

Here's the syntax:

if((ceiling(log(${value})) - log(${value})) < 0.00000001, log(${value})+1, ceiling(log(${value})))

One fun thing to note - all of these functions can be used in a custom dimension as well!


This content is subject to limited support.                




0 replies

Be the first to reply!