Nested if condition in filters


(Vishal) #1

Hi ,
Can looker support nested If condition in custom filters. for example , if I have several categories of data to be displayed and only three of them are considered and I need to display these three and rest can fall into ‘Others’ bucket . I do not have permissions to edit LookML/Custom SQL so have to do this in my “look”.

something like :

if(cat = “A”,“A”,(if (cat = “B”,“B”,if(cat = “C”,“C”,“Other”) ))

(Adina Katz) #2

Hi Vishal,

So in a custom filter we can only filter out data. So we could filter for cat = A, B, C but we won’t be able to group cat = D, E, F, etc. into “other”.

We can, however, use a custom dimension to achieve this. We would do this using the nested if() statement you have: if(cat = “A”,“A”,(if (cat = “B”,“B”,if(cat = “C”,“C”,“Other”) ))

This would yield the results:



(Adina Katz) #3

Also, just to answer this question, in case anyone is looking for this specifically: Can looker support nested if condition in custom filters?. We do support nested if() statements in custom filters. An if() statement in a custom filter must evaluate to a yesno. So an if() statement would be of the form: if(yes_no_condition, yes, no) and here is an example of a nested if() statement using this form: if(${view.dimension}=A, if(${view.dimension}=B, yes, no), no).

As a note: this yields the same results as ${view.dimension}=A OR ${view.dimension}=B so for simplicity, you might want to use the latter.