Search code examples
pythondateironpythonspotfire

Date filter and input box for relative date using spotfire


Can someone help me create something that allow me to select relative time periods (input box with last 7, 14, 30 days) AND an ability to select specific date ranges using the date filter in SPOTFIRE ?

I have idea but looks like I need to write a python script. No experience there. Appreciate any help.

What I probably wanna do is:

Write a script that updates whenever your input box gets updated. The script you first check to see if the value is 0 or null (depending on which you choose). If it is, it would delete the data limiting expression for the visualization. If the input box has a valid value in it then it would need to (a) reset the date filter so all values are selected and (b) set the data limiting expression for the visualization to [Date] > Max(DateAdd(‘dd’, -${p.NumberOfDays}, [Date]))


Solution

  • I used the technique detailed here: https://community.tibco.com/questions/calculated-date-filters

    I created a drop down list control in the text area, named the property NextNDays and set the Expressions =

    For next 30 days:
    Display Name = "Next 30 Days"
    Expression = "If(DateDiff('day',DateTimeNow(),[MY_DATE_FIELD]) < 31 and [MY_DATE_FIELD] > DateTimeNow(),True)"
    
    For next 60 days:
    Display Name = "Next 60 Days"<
    Expression = "If(DateDiff('day',DateTimeNow(),[MY_DATE_FIELD]) < 61 and [MY_DATE_FIELD] > DateTimeNow(),True)"