Announcements
This site is in read only until July 22 as we migrate to a new platform; refer to this community post for more details.

If or Contains Table Calculation

StacyC
New Member

Ok so I’m not really the sure the best way to go about this.  I’m looking to create a calculation that will return a YES is the Unit Name  contains a # or digit but not just a digit it could have letters too.

I can’t make these work…

contains(${units.unit_name},Digit)

If(${units.unit_name},(0,1,2,3,4,5,6,7,8,9))

0 2 3,998
2 REPLIES 2

Contains is a string function so if a “digit” is a number, that will fail. If this is a field that would be used frequently, I would move it to LookML and use SQL “IN”, something that is missing from table calculations unfortunately

Hi Stacy!

You can create a table calculation with the following code example:

if( contains(${units.unit_name},"1") = yes
OR contains(${units.unit_name},"2") = yes
OR contains(${units.unit_name},"3") = yes
OR contains(${units.unit_name},"4") = yes
OR contains(${units.unit_name},"5") = yes
OR contains(${units.unit_name},"6") = yes
OR contains(${units.unit_name},"7") = yes
OR contains(${units.unit_name},"8") = yes
OR contains(${units.unit_name},"9") = yes
OR contains(${units.unit_name},"0") = yes ,yes,no)

This table calculation code the following output:

c929f818-6832-473a-a80a-3a32bfc62e47.png
cbe4fe83-ef3b-427f-a946-2df64b82e049.png

Explanation:

Units_name dimension is a “string” type, that is the reason we need to use double quote numbers in the “if statement” .

Best regards,

Leo

#tablecalc #string #number #contains 

Top Labels in this Space
Top Solution Authors