2 Replies Latest reply on Aug 4, 2016 6:15 AM by Benjamin Greene

    Filter on Table Calculation Not Working as Expected

    Benjamin Greene

      While messing around with latitude-longitude distance calculations in Tableau, I stumbled upon an issue with filtering on table calculations. In the attached packaged workbook, I made a map of cities within the United States. Then, using parameters and some distance calculated fields I found online, I set up the view such that you can enter an Origin City and a Radius and Tableau will filter on any cities within that radius of the origin. Finally, I made another calculated field that distinguishes both the origin city and the farthest city away from the origin from the rest.


      As you can see in the workbook, reducing the radius parameter causes Tableau to filter out more distant cities (as expected), but the Max Distance calculation does not seem to be recalculating to find the farthest city within the new radius. My gut tells me the issue has something to do with the order of when Tableau calculates table calculations and filters, but that's just a guess. Anyone have any idea how to get Tableau to calculate the WINDOW_MAX after applying the Radius Filter?

        • 1. Re: Filter on Table Calculation Not Working as Expected
          Carl Slifer

          Hi Benjamin,


          You are very close to the correct solution. There is not a way that I know if to make that filter happen before the other table calculation. However you can treat the filter as part of the calculation. Its not really filtering at the same time the window_max() is being called it is being used during the calculation then:


          IF WINDOW_MAX(IF [Distance]<= [Radius] THEN [Distance] ELSE 0 END)=[Distance]

          OR [Origin City]=ATTR([City, State])

          THEN "YES"

          ELSE "NO"



          All I've changed here is to see if the distance between cities is less than the radius. If it is then use the disance if its greater it makes everything else 0. So the ones within the radius are the only ones every counted.


          Neat idea. I like it. Well done.



          Carl Slifer


          • 2. Re: Filter on Table Calculation Not Working as Expected
            Benjamin Greene

            Thank you, Carl! That is a very clever workaround. That minor change makes it behave exactly as I intended. Thanks again.