KNOWLEDGE BASE

Using Parameters to Pass a Relative Date Filter With Url Action


Published: 16 Feb 2017
Last Modified Date: 20 Jul 2023

Question

How can parameters be used to pass a relative date filter value to a URL action?

Environment

  • Tableau Desktop
  • Tableau Server
  • Linking views using URL actions

Answer

  1. Create two parameters to work as date range filters:
    1. The "Amount" - how many units of the date part do we want relative to Today? (Or anchor date)
      • Create a parameter that has an integer format, and allows all values.
    2. The "Date Part" - which date part to use relative to Today? (Days, weeks, months, etc.)
      • Create a parameter that has a string format, and allows a list of values.
      • Populate the list with the dateparts you want to be able to use for the relative date filter, ex: "Days", "Weeks", "Months", "Years"
  2. Create a calculated field to use as a filter for the parameter controls:
    • IF [Date Part]="Days" THEN 
      (IF DATEDIFF('day',[Date Field],TODAY())<=[Amount] THEN "Show" ELSE "Hide" END)
      ELSEIF [Date Part]="Weeks" THEN 
      (IF DATEDIFF('week',[Date Field],TODAY())<=[Amount] THEN "Show" ELSE "Hide" END)
      ELSEIF [Date Part]="Months" THEN 
      (IF DATEDIFF('month',[Date Field],TODAY())<=[Amount] THEN "Show" ELSE "Hide" END)
      ELSEIF [Date Part]="Years" THEN 
      (IF DATEDIFF('year',[Date Field],TODAY())<=[Amount] THEN "Show" ELSE "Hide" END)
      END
  3. Drag the calculated field onto the "Filters" shelf, and select "Show" to keep. 
  4. Create calculated fields to use as URL controls:
    1. [Amount URL]
      • "Amount="+STR([Amount])+"&"
    2. [Date Part URL]
      • "Date%20Part="+[Date Part]
  5. Make sure the URL control calculated fields are on the Details shelf in the view(s) that are the target of the URL action(s).
  6. Create the URL action(s) with the following format for the URL:
    • <worksheet URL>?<Amount URL><Date Part URL>
Did this article resolve the issue?