Avoid duplication of SQL logic of different measurements

Hello,

In my project we have a lot of measurements which tend to share the same common SQL logic applied for a column. 

For example:

measure: column_apple_agg {
type: number
sql: floor(sum(${apple_weight}));;
}

For simplicity I put only 2 SQL functions (floor and sum), but it can easily be more complex.

Is there any way to avoid copy/paste of this common logic in SQL applied for a column? 
Something like 'templated' measure or any other templating mechanism which could help here.
I did my best searching in the docs and checking all DRY Looker's recommendations, but couldn't find an answer.

Thank you.

0 1 130
1 REPLY 1

Hi there,

Thanks for bringing this up.  While I don't believe we have quite the templating mechanism that you're interested in based on your description I did want to bring up how Looker works with symmetric aggregates.  You'll want to avoid aggregating in the SQL for your measures, and use the type to define that.  More information can be found here: https://cloud.google.com/looker/docs/best-practices/understanding-symmetric-aggregates

 

 

Top Labels in this Space
Top Solution Authors