Use For loop in Lookml

Hi All,

For my use case, I would want to assign a variable whose original value would be 0 but based on a certain dimension's value I can add values to a variable and then call it as a different column.

Something like this:

variable = 0

for i in range(0, length of the column amount):

if code in ['deposit', 'accelerate', ]:
variable += amount

if variable < 0:

variable = 0

and then return the variable as a dimension/measure.

 

Code and amount are two dimensions used in the view.

The reason I'm looking for a loop is that the calculation (add, sub) can only happen in a specific order.

Let me know if any additional info would help.

0 1 310
1 REPLY 1

Hi @Saurabh_Sharma 

LookML is a scripting language that helps in making the SQL generation dynamic and flexible. It is not a programming language like python where we can write a for loop.

That being said, your explanation above does not bring out the logic you want to achieve. Can you use some sample data and then explain your requirement and end goal?

~Ashish

Top Labels in this Space
Top Solution Authors