cancel
Showing results for 
Search instead for 
Did you mean: 

Date Filters - List

donnyduwitt
7 - Data Storage
7 - Data Storage

I have a dashboard that looks at diversity and demographic information for my company, and a key piece of its functionality is the ability to select a specific month/year so our users can view information from any number of points in time.  The way I currently have it set up is that it is a month filter and a radio button - so only one month can be selected and displayed at a time.

My question is that as time goes on, new months will be populated and placed at the top of my filter list - is there a way to have the filter default to the most recent date in the filter?  For example, when I designed this in Feb 2024 I set my default filters to that date.  When March 2024 was populated, the default filter stuck on February 2024 - ideally, I would like the default filter to roll up to the most recent available date.  Has anyone encountered this before/have a solution besides updating the default filters every month?

4 REPLIES 4

rapidbisupport
11 - Data Pipeline
11 - Data Pipeline

Hi @donnyduwitt ,

The way I've achieved this in the past is to have the dashboard script always set the current month in the filter when initialized. The dashboard script below finds the current month (relative to the viewers browser) and then sets this as the value of the date filter specified as dateFilter.

dashboard.on('initialized', (d, args) => {

  const date = new Date()
  let month = (date.getMonth() + 1) > 9 ? date.getMonth() + 1 : `0${date.getMonth() + 1}`
  const year = date.getFullYear()
  const formattedDate = `${month}/${year}`

  let dateFilter = {
    jaql: {
      "datatype": "text",
      "dim": "",
      "title": "",
      "column": "",
      "table": "",
      "collapsed": true,
      "isDashboardFilter": true,
      "merged": true,
      "filter": {
        "explicit": true,
        "multiSelection": false,
        "members": [
          `${formattedDate}`
        ]
      }
    }
  }

  // Set up the filter update options (overwrite/leave current filters, etc.)
  var filterOption = {
    save: true,
    refresh: true,
    unionIfSameDimensionAndSameType: false
  }

  // Apply the update specified above
  prism.activeDashboard.filters.update(dateFilter, filterOption)
})

You'll need to adjust the dateFilter jaql to align with the date filter you have currently on the dashboard (you can see this in the console using prism.activeDashboard.filters.$$items and look through this object for the corresponding date filter).

Additionally, the format of the item may be different based on how your filter works, etc. so might also need adjustment.

I'm happy to provide a consult if you'd like to look more deeply or have any issues implementing:

Sisense Services | Free 30-Minute Sisense Consultation (rapidbi.com.au)

Let me know how you go?

Hi Daniel,

Thanks for your assistance with this.  I was able to use your script above and modify it to fit my date filter, however I run into one issue.  While it achieves the desired goal of retrieving the most recent date in the filter, it eliminates all past dates and the filter is empty except for the most recent value.  I've found that if I select 'restore my default filters' in the filters pane, my list of dates reappears, so there is a somewhat workaround we can use with its current functionality.  However, I'd like to see if there is a way we can have the list present and the most recent date as the default without having the end user restore the filters.  Attached are screenshots of the filter pre restore and post restore.  Thanks again for any advice you may have!

Hi @donnyduwitt ,

I think it's to do with our filter dateFilter jaql.

Can you try to remove all properties from the filter jaql except for the 'dim' and the 'filter'

  let dateFilter = {
    jaql: {
      "dim": "",
      "filter": {
        "explicit": true,
        "multiSelection": false,
        "members": [
          `${formattedDate}`
        ]
      }
    }
  }

The way we're tackling this should preserve the ability to select - but my guess is that our jaql object and the original are inconsistent in some way, breaking the way Sisense asks itself for the list of available members for the item.

I'd be happy to jump on a call to get more specific here (sometimes these things much easier over a screen share):

Sisense Services | Free 30-Minute Sisense Consultation (rapidbi.com.au)

Let me know how you go?

Benji_PaldiTeam
11 - Data Pipeline
11 - Data Pipeline

Hi @donnyduwitt ,

This is a very common use case and we have a FREE plugin that solves this among other rules you can set on your dashboard filters.

Here is a link to the plugin page: https://www.paldi.solutions/plugins/adaptive-default-filters

Feel free to reach out and get it today 🙂 

 

Paldi Solutions - Number #1 Sisense Plugins Developer