Spotfire Report Filter Default Max Date

5.6k views Asked by At

I have a spotfire report which refreshes everyday and this refresh adds a business day (i.e. 6/21, next refresh will add 6/22 and so on). I want my filter (range filter) to always point to the latest date by default (i.e. today it will point to 6/21, tomorrow 6/22 and so on) How do I implement this?

2

There are 2 answers

3
user3472649 On BEST ANSWER

Another way is to use a calculated column that generates a filter for "Max Date". This calculated column will get recalculated every time the data refreshes.

For example, if a column is created with this calculation:

if ([mydateColumn]=Max([mydateColumn]),"Yes","No")

Just set the filter to "Yes" and when the data refreshes the dashboard will always default to showing the latest date.

2
clesiemo3 On

There are 2 different ways I would do this: Python script activated with property change or button OR an expression in your visualizations.

If you would like to do a Python Script and don't mind users/yourself clicking a button or already have Document Properties that change you could trigger off of them, then try this:

TABLE is a parameter of the table I'm targeting the change for. However you can loop through tables or call it out specifically in the code.

from Spotfire.Dxp.Application.Filters import RangeFilter
from Spotfire.Dxp.Application.Filters import ValueRange

for scheme in Document.FilteringSchemes:
    #get our RadioButtonFilter; Other filter types work as well
    filt = scheme.Item[TABLE].Item[TABLE.Columns.Item["DATE_COL"]].As[RangeFilter]()
    #filt will be NoneType if that column is a different filter type
    if filt is not None:
        top = filt.ValueRange.High
        #Set the lower and upper bound to the existing upper bound
        filt.ValueRange = ValueRange(top,top) 

Alternatively, if you'd prefer to have it just set up on its own without any scripting you can filter each visualization individually with the following expression placed into your "Limit by Expression" section under the Data Tab in the visualization's properties:

[DATE_COL] = Date(DateTimeNow())

Python has its advantage of covering the whole document (including newly created visuals) but requires a button to set it off or Javascript to automate it which may lead you to want to use the limit by expression option.

In one of my previous answers I go through utilizing JavaScript to automated button clicking of python scripts: Spotfire Export Automatically. I have run into a couple issues with the JS not working in the web player but it might be cross site issues with how we set up our web player server here. Works great in the desktop version though for sure.