It may be desired to fix a filter to certain values so that the dashboard shows only that specific data when opening it. This is possible by using filter initialization option. As explained in this article you can set up such filter initialization from inside the editor or on the token.

Setting this up via the token allows you to set a different selection based on the specific user looking at the dashboard. This may be particularly interesting when the values available are different per user.

But then the next question may become: how do I know to which value to initialize?

A frequent request is to initialize it to the first value available for a specific user.
In this article we cover the different steps to follow to do just so!

  1. Create an Embed token with the users' multitenancy properties
  2. Query the data API endpoint with the Embed token to retrieve the first value available to the user
  3. Create a new Embed token adding the initialization filter
  4. Load the dashboard with the new Embed token

1. Create an Embed token with the users' multitenancy properties

As a first step, you create an Embed token as normally specifying all the user specifics including any of the mulitenancy properties (account_overrides, parameter filters, ...) needed for that user.

We are creating this Embed token so that when we query for the data with it in step 2, we get the data as the user will get it when loading the dashboard.

2. Query the data API endpoint with the Embed token to retrieve the first value available to the user

With the Embed token from step 1, you will now query via our data API endpoint to retrieve the data as it would be displayed in the filter you want to initialize.

As seen in this Developer docs guide on querying a dataset via the API, you can use the call below to retrieve the data.

Elements of note in this call are:

  • Specify the column and dataset ID added to your filter item as dimensions
  • If you have any filters active on your filter item, you will want to add these as where criteria. More info here
  • Specify a limit by 1 to only retrieve 1 data element. Increase this number as desired in case you want to initialize to the first 5 values, for example.
curl https://api.luzmo.com/0.1.0/data 
{
    "action": "get",
    "version": "0.1.0",
    "key": "< your embed key >",
    "token": "< your embed token >",
    "find": {
        "queries": [
            {
                "dimensions": [
                    {
                        "column_id": "< column used in the filter widget >",
                        "dataset_id": "< dataset id used in filter widget >"
                    }
                ],
                "where": [
                    {
                        "expression": "<expression>",
                        "parameters": [
                            {
                                "column_id": "< column used in the filter widget >",
                                "dataset_id": "< dataset id used in filter widget >"
                            },
                            "< your value >"
                        ]
                    }
                ],
                "order": [
                    {
                        "column_id": "< column used in the filter widget >",
                        "dataset_id": "< dataset id used in filter widget >"
                        "order": "asc"
                    }
                ],
                "limit": {
                    "by": 1
                }
            }
        ]
    }
}

3. Create a new Embed token adding the initialization filter

Next we will create an Embed token like in step 2 but also adding the initialization filter. More details on how an initialization filter is configured for a Dropdown or Slicer filter can be found in this Academy article.

An example for initializing with a hierarchy value would be:

{
  "clause": "where",
  "chart_id": "< chart id of a filter object contained in the dashboard >",
  "expression": "? in ?",
  "value": [
	  "online payment"
  ]
}

4. Load the dashboard with the new Embed token

Finally, you can load the dashboard with the Embed token obtained in step 4, as you would at the end of any embedding process (described in this Academy article).

Need more information?

Do you still have questions? Let us know how we can help.
Send us feedback!