3 Replies Latest reply on Oct 25, 2011 1:48 PM by derekfarren

    referencing Filter variables in Formulas

    . Mar

      Hello,

       

      Is it possible to reference a filter variable in formulas? If yes what is the syntax?

       

      I need to create a calculated field that is based on the Date filter.

      Example: if isnull([discharge_day] ) then

      DATEDIFF("day",[admit_date],MAX(Year-the date set in the Date filter)MAX(MONTH Filter) MAX(DAY filter))

      else

      DATEDIFF("day",[admit_date],[discharge_date])

       

       

       

      Thanks

        • 1. Re: referencing Filter variables in Formulas
          James Baker

          What about just using MAX([Date])?  If you use that calculated field in a context where those year/month/day filters are applied, would that do the job?

           

          Edit: whoops, strike that, that's totally bogus.  (You can't put an aggregate calc in a row-level calc like that!)  Uh, I think the only way to get your calc to come out correctly is to hard code the date directly in the formula.  (Or put the date by itself in another calculated field to ease maintenance a little bit.)  Sorry.

          • 2. Re: referencing Filter variables in Formulas

            Again,  it would be of interest to learn how to get user input (quick filter) into a formula field.  I would think this would be elementary, but perhaps not.....  The question is often eluded.

             

            "Is it possible to reference a filter variable in formulas? If yes what is the syntax?"

            • 3. Re: referencing Filter variables in Formulas

              From my understanding, no, it is not possible because it seems like Tableu processes the filters after it processes the formulas. So, the filter value is not available when Tableau is making the formula calculation.

               

              Nevertheless, if you create a parameter instead of a filter you can do that. The parameter can have the same functionality than the filter, you just have to add it on the measure calculation you are filtering. And you can have a parameter control on the sheet (same as a quick filter).