If or Contains Table Calculation

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))

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:

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