Documentation Index
Fetch the complete documentation index at: https://cubed3-docs-cub-2416-update-semantic-snowflake-semantic-vie.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Use case
In some cases we may want to let a user select a filter value and be able to use that value in calculations without filtering the entire query. In this example, we want to know the ratio between the number of people in a particular city and the total number of women in the country. The user can specify the city for the filter. The trick is to get the value of the city from the user and use it in the calculation. In the recipe below, we can learn how to join the data table with itself and reshape the dataset!Data modeling
Essentially what we will be doing is allowing the user to select a specific city value, then cross joining that value with the rows in the data table. This will maintain the orginal number of rows in the dataset while adding a new column that has the value that the user chose. This will allow us to use that value in our calculations. In this case, we will use that value to filter a single metric so that we can compare that metric with the whole population. Let’s explore theusers cube data that contains various information about
users, including city and gender:
| id | city | gender | name |
|---|---|---|---|
| 1 | Seattle | female | Wendell Hamill |
| 2 | Chicago | male | Rahsaan Collins |
| 3 | New York | female | Megane O’Kon |
| … | … | … | … |
FILTER_PARAMS
parameter in the sql of the cube. This will allow us to apply to the filter to a subquery
rather than the whole query so that it doesn’t affect other calculations.
In this use case, we can join the data table with itself to create a new city_filter
column with a single value that the user chose so that we can use it in other calculations.
Result
By joining the data table with itself and filtering oncity_filter, we get the
ratio for the chosen city without affecting the total denominator. For example,
when filtering for Seattle:
| total_number_of_women | number_of_people_in_city | ratio |
|---|---|---|
| 259 | 99 | 38.22% |