dougadam79
08-08-2023Data Storage
Filter based on one filter selection OR another
Hi, Apologies if straightforward but i'm having issues with a conditional filter scenario on my dashboard. I have two Date Range Filters on my dashboard (one created date and the other modified date...
- 08-17-2023
Hi dougadam79,
Below is an example dashboard script that you can use to apply an either/or logic between two dashboard date filters. The script only requires two inputs: the names of the date filters. You can specify those names in the second and third lines of the code.
I also attached a sample dashboard with the script included. It uses the Sample Healthcare cube. For some reason, this site doesn't let me attach a .dash file, so I had to change the extension to .txt. Please change it back to .dash before you import the file to your environment.
Let me know if you have additional questions.
-Tri
//Specify the names of the two filters, this is the only part of the code that requires your input var date1Name = 'Admission Time'; var date2Name = 'Discharge Time'; //Find the first date filter by name var date1Filter = dashboard.filters.$$items.find((item) => { if (item.jaql && item.jaql.title.indexOf(date1Name) !== -1) { return true; } }); //Get the original JAQL filter state of the first date filter var date1FilterJAQL = date1Filter.jaql.filter; //Find the second date filter by name var date2Filter = dashboard.filters.$$items.find((item) => { if (item.jaql && item.jaql.title.indexOf(date2Name) !== -1) { return true; } }); //Get the original JAQL filter state of the second date filter var date2FilterJAQL = date2Filter.jaql.filter;; //Every time a filter is changed, this code is executed dashboard.on('filterschanged',function(d) { //Find the first date filter by name again and add it to a new variable to hold the new filter values date1Filter_new = dashboard.filters.$$items.find((item) => { if (item.jaql && item.jaql.title.indexOf(date1Name) !== -1) { return true; } }); //Get the new JAQL filter state of the first date filter var date1FilterJAQL_new = date1Filter_new.jaql.filter; //Check if either date is already set to Include All if(!(date1Filter.jaql.filter.all == true || date2Filter.jaql.filter.all == true)) { //Check if the new filter state is different from the original filter state, which means the filter has been modified if(date1FilterJAQL_new != date1FilterJAQL) { //If so, then reset the second date filter to Include All date2Filter.jaql.filter.all = true; } //Update the value of the original filter state with the new filter state date1FilterJAQL = date1FilterJAQL_new; } //Find the second date filter by name again and add it to a new variable to hold the new filter values date2Filter_new = dashboard.filters.$$items.find((item) => { if (item.jaql && item.jaql.title.indexOf(date2Name) !== -1) { return true; } }); //Get the new JAQL filter state of the second date filter var date2FilterJAQL_new = date2Filter_new.jaql.filter; //Check if either date is already set to Include All if(!(date1Filter.jaql.filter.all == true || date2Filter.jaql.filter.all == true)) { //Check if the new filter state is different from the original filter state, which means the filter has been modified if(date2FilterJAQL_new != date2FilterJAQL) { //If so, then reset the first date filter to Include All date1Filter.jaql.filter.all = true; } //Update the value of the original filter state with the new filter state date2FilterJAQL = date2FilterJAQL_new; } });