Getting Creative with Constants

Once you've spent a bit of time working with LookML you’ll probably agree that it’s not exactly a concise language, and you’re often repeating certain values and strings.

LookML constants can go some way to helping with this. One trick is to use constants to define repeated string literals, especially view labels and group labels. By defining these strings as constants in your project manifest file, developers can then reference the constant in their label parameters.

This has the advantage of giving suggestions when you type - if you use meaningful names for your constants you can make it easy for developers to choose the right one. Another benefit is that your labels should be consistent, and you can avoid the situation when a slight difference between view labels means you end up with two similar groups in your field picker.

Another creative use for constants is to store file paths for includes. You get the same benefits of consistency and suggestions, and Looker will resolve the string values and include the file correctly. This could be particularly useful if you organise your includes into separate files themselves so that developers can get suggestions of which file-of-includes to use.

Someone at Looker also suggested you can use constants for storing SQL snippets as well as Liquid expressions - both nice ideas, althigh you won't benefit from syntax highlighting with these.

Previous
Previous

if dev/if prod SQL conditionals

Next
Next

Row-wise MoM Calculations