In Data Queries for Insights - Basic you’ve learned how to create a basic Insights Query using static filters.
Dynamic filtering allows you to select values from a menu to filter the values shown on any chart or graph on the dashboards.
There are several cases where you would need to define a dynamic filter:
- To filter the data based on a property of the current User or Account. For example – to filter on the current User's division or territory property.
- To filter the data based on a user selected value from a drop down. For example - to filter the data shown in a chart by a specific brand.
- To filter the data based on a condition. For example – if the User chose a brand, filter on this brand, otherwise, do not do filter on the brand.
Dynamic filter based on a dynamic value
Dynamic filter of the data is based on defining a variable in the data query, filtering the data according to this variable's value and passing a value from the page to the query.
Define a data query with parameter
Send value from the page to the query variable
Define page parameters, set them with a value, and pass values to the query
Define a data query with parameter
The dynamic filter data query is defined as a regular data query except for the following additions:
- Add a variable to the data query by clicking on the Add button in the Input Variables section.
- Name – the name of the variable
- Type – the variable type. Usually, it will be a String
- Default value – the value to use if the variable is not passed to the query. This is optional as it is best practice to always pass values to the query variables.
- Preview value – the value to use when running the query for the preview of the data (below the series, values will be shown for preview).
- Add the variable to the series filter.
- Edit the series and in the filter section, choose the required property and then choose ‘Equal to (variable)’ or ‘In (variable)’ and select the variable you defined above.
Note: You can define and apply filters with multiple variables.
- In some case, you would need to apply the query filter only if a specific value was sent to the query.
Example:
In a chart showing Monthly Sales - last 12 months with filtering the data shown by the Main Category (or Brand) field, the user can select the Main Category from the menu to show monthly sales only for that Main Category.
If a Main Category was selected by the user, then filter on this value, but if ‘All’ is selected - the default value at the top of the selection menu - then do not apply the filter and show monthly sales for all categories.
In this case, instead of using the variable in the filter section, you can use it in the Conditional filter section, to define that the filtering will be executed only if the condition is met, such as Main Category is not ‘All’.
Thats it! The query can now accept a parameter and it will filter by that parameter.
You can see in the preview area that the data is filtered according to the query variable 'Preview' value. If you will change the variable’s ‘Preview’ value then you will see different data in the preview area.
Send value from the page to the query variable
When defining the query on the page, you can choose to:
- Use the query variable default value.
- Send a static value. In this case you need to write the value you wish to send.
This option is useful for example if you have several insight blocks using the same query (on the same page or different pages), and you wish to use a different static filter in each one.
- Send a dynamic value (page variable). This is detailed below.
Define page parameters, set them with a value, and pass values to the query
Using Page Builder edit the Insights page that you want to use the dynamic query in.
- Click Manage Parameters
- Click Add to add your variable.
- Key - enter the variable name
- Description - enter text description of the variable
- Defaule Value - enter the default value that should be passed to the query. For example - the value "All" that should be displayed if the user did not select anything from the drop down menu.
- To set the page parameter with a value, you have 3 options:
Option 1: If the required value should be selected by the user, such as selecting a Main Category from a filter drop down, then you need to add a filter block to the form. The filter block should be configured with:
-
- The page parameter which will get the selected value
- A flow which has a ‘Get Values’ logic block to return a list of values which will be seen in the drop down.
Option 2: If the required value is static (not changed by the user), such as the User’s division, then set the value via the form’s Load Flow by clicking on the ‘Choose flow’ button of the ‘On load flow’ and select the required Flow.
- The Flow will contain a ‘Search Data’ and an ‘Extract Value’ logic blocks to set the page parameter with a value from a resource.
Option 3: Call this page with the variable's value in a parameter in the URL. This is not recommended because it is difficult to maintain.
Select the page parameters in the variables of the data query in the Insight page Block (Chart, Benchmark Chart).
Go to the 'Content' tab of the query. In Variable mapping -> choose ‘Variable’ and select the page parameter you defined.
0 comments
Please sign in to leave a comment.