Limiting Long Strings Using `value_format`

done
low_priority
reply

(Samuel ) #1

Hi y’all,
I have a question for anyone who would be gracious enough to give me a pointer or two. I have a field in my lookml, where a given query is displayed- yet there are no limits on it. At an explore level, I would like it to be limited to the first 200 characters. I could throw in the SUBSTR() with the actual sql- example

dimension: actual_query {

label: “Query”

description: “The actual query that was ran”

sql: SUBSTR(${TABLE}.actual_query, 0, 200) ;;
}
`

Or something to that effect. This would limit it on all levels though, if one were to be looking through my dashboard, wanted to explore a field with the actual_query on it, it would not show the whole thing. Basically, is there a way that I can limit these giant strings to make them look prettier on my Dashboard Tiles.

Thanks as always,
Morris


(Jackson Alvarez) #2

Whenever i want to leave the underlying values intact, but present something cleaner or just different in dashboards/results, i use the html: parameter, usually in conjunction with someliquid syntax.

For example:

dimension: actual_query {
label: “Query”
description: “The actual query that was ran”
sql: ${TABLE}.actual_query;;
html: {{rendered_value | slice: 0,200 }}
} 

Will return the first 200 characters on the frontend, but if you wanted to filter it or do something with the underlying data you still could operate on the full string.

you can also add if statements to achieve various conditions. Say you had a parameter field like

parameter: show_full_queries {
type: yesno
}

you could then

dimension: actual_query {
label: “Query”
description: “The actual query that was ran”
sql: ${TABLE}.actual_query;;
html: {% if view.showallchars._parameter_value == 'true' %}
     {{ rendered_value }}
     {% else %}
    {{ rendered_value | slice: 0,200 }}
  {% endif %} ;;
} 

And it’ll only show the full strings if that parameter is ticked to yes. You can probably figure something out for your use case!