How to add/remove a filter based on another filter's selection [Linux]
Summary: Thalita Santos, Thalita Santos, provides a detailed guide on how to programmatically manipulate dashboard filters in Sisense, specifically adding or removing a filter based on the presence of another. The solution utilizes the "filterschanged" event within the dashboard script to create dependent filter logic, where one filter (Filter A) controls the status of another (Filter B). The code is designed to work for both cloud and on-premise deployments and includes safeguards to prevent infinite loops during filter updates. This guide is intended to ensure business rules are enforced on dashboards and offers a flexible starting point that can be customized as per user needs.
Introduction
This article demonstrates how to programmatically add or remove a dashboard filter in Sisense when another specific filter is added or removed. The solution is tested on Sisense L2026.2.1-c and works for both cloud and on-premises deployments. By following this guide, you can create dependent filter logic where one filter automatically controls the presence of another.
Step-by-step guide
1. Prepare your environment
Create a new dashboard or go to an existing dashboard. Make sure you have at least one filter already added to the dashboard (this will be your "trigger" filter — Filter A).
2. Apply the code
Go to your dashboard, click on the three dots menu at the dashboard level and select Edit Script, then paste the following code:
var isUpdatingFilterB = false;
var filterADim = "[Brand.Brand]"
var filterBDim = "[Brand.Brand ID]"
dashboard.on("filterschanged", function (args) {
if (isUpdatingFilterB) return;
// Find Filter A: [Brand.Brand]
var filterA = dashboard.filters.$$items.find(function (f) {
return f.jaql && f.jaql.dim === filterADim;
});
var filterOptions = {
save: false,
refresh: true,
doNotTriggerChange: true,
};
isUpdatingFilterB = true;
try {
if (
filterA &&
filterA.jaql.filter &&
filterA.jaql.filter.members &&
filterA.jaql.filter.members.length > 0
) {
// Filter A is active with selected members — apply Filter B
var filterBJaql = {
jaql: {
dim: filterBDim,
datatype: "text",
title: "Brand ID",
filter: {
explicit: true,
multiSelection: true,
members: ["12"], // Apply as 12 - adjust if you need specific members
},
},
};
dashboard.filters.update(filterBJaql, filterOptions);
} else {
// Filter A is removed or set to Include All — remove Filter B
var existingFilterB = dashboard.filters.$$items.find(function (f) {
return f.jaql && f.jaql.dim === filterBDim;
});
if (existingFilterB) {
dashboard.filters.remove(existingFilterB, filterOptions);
}
}
} finally {
// Reset the flag after a short delay to allow the update to complete
setTimeout(function () {
isUpdatingFilterB = false;
}, 300);
}
});

3. Code explanation
In this example we are listening for the filterschanged event at the dashboard level. When any filter changes, the script checks whether Filter A ([Brand.Brand]) is active with selected members. If it is, Filter B ([Brand.Brand ID]) is automatically applied with the specified members. If Filter A is removed or set to "Include All," Filter B is automatically removed from the dashboard.
The isUpdatingFilterB flag prevents an infinite loop — since adding/removing Filter B would itself trigger filterschanged, the flag ensures the script ignores its own changes. The flag is reset after a 300ms delay using setTimeout to allow the filter update to complete before the script becomes responsive again.
This is a dashboard script (not a widget script), so it applies globally to the entire dashboard regardless of which widget is selected.
Conclusion
By leveraging the filterschanged dashboard event, you can create dependent filter relationships where one filter automatically controls the presence of another. This approach is useful when you need to enforce business rules — for example, always applying a secondary filter whenever a user selects a specific dimension value. The provided script is a flexible starting point — feel free to adjust the dimension names, member values, and logic to match your specific use case.
References/Related content
Disclaimer: This post outlines a potential custom workaround for a specific use case or provides instructions regarding a specific task. The solution may not work in all scenarios or Sisense versions, so we strongly recommend testing it in your environment before deployment. If you need further assistance with this, please let us know.