0

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?

Scarlet Knight
  • 139
  • 4
  • 10

2 Answers2

2

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.

1

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.

Community
  • 1
  • 1
clesiemo3
  • 1,099
  • 6
  • 17
  • I would like it to happen automatically, so looking at option 2; If I am limiting data using the expression, how can the user select a previous date? – Scarlet Knight Jul 01 '15 at 18:02
  • Hmm... Good question. They couldn't adjust it with Option 2. I had assumed you just wanted always set to the last date rather than it being the default but still changeable. There's probably other fun ways around this that you could use custom filters or something with python that set the Limit by Expression for your visualizations but I think the simplest way is how @user3472649 did it. The end user would just have to click ALL or check "No" to "unlock" the range to use as normal. – clesiemo3 Jul 02 '15 at 13:58