Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
I livelli possono essere un ottimo modo per raggruppare i valori. Tuttavia, con le dimensioni type: tier di LookML, questi bucket sono predefiniti e statici. A volte potresti voler creare un livello dinamico che consenta agli utenti di modificare le dimensioni del bucket. Puoi farlo in Looker utilizzando i campi con solo filtri (chiamati parametri parameter) in combinazione con un linguaggio di creazione di modelli (chiamato Liquid).
Crea un parametro type: number da utilizzare come campo di filtro della parte anteriore in cui l'utente può inserire la dimensione numerica del bucket che preferisce.
Crea una dimensione che faccia riferimento al valore del parametro con la variabile Liquid {% parameter parameter_name %}. Questa dimensione determina i vari bucket e modifica dinamicamente le dimensioni del bucket in base al valore inserito dall'utente nel campo del filtro frontend (parametro parameter).
Ad esempio, uno sviluppatore crea un livello di età dinamico che consente agli utenti di raggruppare i valori di età in base a intervalli personalizzati:
La sintassi SQL per il seguente esempio potrebbe dover essere adattata al dialetto del database.
Ora un utente può scegliere i valori di livello per la colonna Età in un'esplorazione. Ad esempio, un utente potrebbe voler visualizzare le età raggruppate in bucket di 10 anni e quindi inserire il valore 10 nel filtro Dimensione del bucket della fascia d'età:
L'espressione SQL nella dimensione dynamic_age_tier divide un valore di età della colonna ${TABLE}.age sottostante, ad esempio 25, per il valore del parametro 10, ottenendo 2,5. Il valore 2,5 viene troncato a 2 dalla funzione TRUNCATE e moltiplicato per il valore del parametro 10, ottenendo 20. 20 diventa il bucket; qualsiasi valore compreso tra 20 e 29 anni è incluso nel bucket 20.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-07-31 UTC."],[],[],null,["# Creating dynamic tiers\n\nTiers can be a great way to bucket values. However, with LookML [`type: tier`](/looker/docs/reference/param-dimension-filter-parameter-types#tier) dimensions, those buckets are predefined and static. Sometimes you may want to create a dynamic tier that lets users change the bucket size. You can do this in Looker using filter-only fields (called [`parameter` parameters](/looker/docs/reference/param-field-parameter)) in conjunction with a templating language (called [Liquid)](/looker/docs/liquid-variable-reference).\n\n\nYou can also use [custom binning](/looker/docs/custom-fields#custom_binning) to create dynamic tiers natively in Explores when you have [permission to create or edit custom fields](/looker/docs/admin-panel-users-roles#create_custom_fields).\n\n\nTo create a dynamic tier:\n\n1. Create a parameter of `type: number` to serve as the frontend filter field where the user can enter the numerical bucket size they would like.\n2. Create a dimension that references the parameter value with the Liquid variable [`{% parameter parameter_name %}`](/looker/docs/liquid-variable-reference#liquid_variable_definitions). This dimension determines the various buckets and will dynamically change the bucket size to the value entered by the user in the frontend filter field (the `parameter` parameter).\n\n\nFor example, a developer creates a dynamic age tier that lets users bucket age values by custom ranges:\nThe SQL syntax for the following example may need to be adapted to suit your database dialect. \n\n```\n parameter: age_tier_bucket_size {\n type: number\n }\n\n dimension: dynamic_age_tier {\n type: number\n sql: TRUNCATE(${TABLE}.age / {% parameter age_tier_bucket_size %}, 0)\n * {% parameter age_tier_bucket_size %} ;;\n }\n```\n\n\nA user can now choose tier values for the **Age** column in an Explore. For example, a user might want to see ages grouped into 10-year buckets and so enter the value **10** in the **Age Tier Bucket Size** filter:\n\n\nThe SQL expression in the `dynamic_age_tier` dimension divides an age value from the underlying `${TABLE}.age` column --- for example, 25 --- by the parameter value of 10, resulting in 2.5. The value 2.5 is truncated to 2 by the `TRUNCATE` function and is multiplied by the parameter value 10, resulting in 20. 20 becomes the bucket; any age value between 20 and 29 is included in the **20** bucket.\n\n\u003cbr /\u003e"]]