Getting unique values for a field
Use case
We have a dashboard with information about the users, and we’d like to filter them by city. To do so, we need to display all unique values for cities in the dropdown. In the recipe below, we’ll learn how to get unique values for dimensions.Data modeling
To filter users by city, we need to define the appropriate dimension:Query
It is enough to include only a dimension in the query to get all unique values of that dimension:Result
We got the unique values of thecity dimension, and now we can use them in the
dropdown on the dashboard:
Choosing dimensions
In case we need to choose a dimension or render dropdowns for all dimensions, we can fetch the list of dimensions for all cubes from the/meta endpoint:
Source code
Please feel free to check out the full source code or run it with thedocker-compose up command. You’ll see the result, including
queried data, in the console.