Deepthi gopal
Deepthi gopal

Reputation: 43

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]))

Upvotes: 1

Views: 2297

Answers (2)

Paul Jacobson
Paul Jacobson

Reputation: 44

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)"

Upvotes: 1

S3S
S3S

Reputation: 25122

Careful on asking XY Problems but in your case you could just use this expression in the Limit Data Using Expression box of what ever visualization want to be affected.

[Date] >= DateAdd('dd', ${p.NumberOfDays} * -1, [Date])
AND
[Date] < DateTimeNow()

Note, if [Date] is a DateTime type, you need to cast it as a date to eliminate you missing partial dates.

[Date] >= DateAdd('dd', ${p.NumberOfDays} * -1, Cast([Date] as Date))
AND
Cast([Date] as Date) <= Cast(DateTimeNow() as Date)

Upvotes: 1

Related Questions