When displaying aggregated data, sometimes it's important to have a minimum number of results before displaying the data. This is critical when displaying anonymous aggegated user data in order to avoid situations where a single user's data could be exposed.
In order to create this functionality, we will need to use a "having" filter. These filters are not currently supported throuh the UI, so we will add them during Embed token authorization. The value we set in the filter will be the minimum number of results that must be present for data to show; in this example we will use 5.
Example java script call to add "having" filters to a chart:
const Luzmo = require('@luzmo/nodejs-sdk');
var client = new Luzmo({
api_key: '< Your API key >',
api_token: '< Your API token >'
});
client.create('authorization', {
type: 'embed',
username: '12345678',
suborganization: 'Burrito Co.',
name: 'Embed user',
email : 'embed_user@example.com',
expiry: '24 hours',
// Add a initialization filter
filters: [
{
clause: 'having',
origin: 'chart',
chart_id: '< chart id >',
securable_id:'< dataset id >',
column_id:'< column id >',
aggregation: { type: 'count' }
expression: '? > ? ',
value: 5
}
]
}).then((result) => {
/*
The embed authorization key and token can be found in result.id and result.token, respectively.
The specified filters can be found in result.filters.
*/
console.log(result);
});
To apply the minimum results filter to all charts on the dashboard, set the filter as a "global filter" instead:
const Luzmo = require('@luzmo/nodejs-sdk');
var client = new Luzmo({
api_key: '< Your API key >',
api_token: '< Your API token >'
});
client.create('authorization', {
type: 'embed',
username: '12345678',
suborganization: 'Burrito Co.',
name: 'Embed user',
email : 'embed_user@example.com',
expiry: '24 hours',
// Add a initialization filter
filters: [
{
clause: 'having',
origin: 'global',
securable_id:'< dataset id >',
column_id:'< column id >',
aggregation: { type: 'count' }
expression: '? > ? ',
value: 5
}
]
}).then((result) => {
/*
The embed authorization key and token can be found in result.id and result.token, respectively.
The specified filters can be found in result.filters.
*/
console.log(result);
});