2 Replies Latest reply on Nov 1, 2018 1:29 PM by Milankumar Patel

    Median with Weights

    Milankumar Patel



      I have seen there are a few posts which explains about weighted median, but none of them working in my attempt.


      I have a variable which is about the price people pay for some service.. It is derived from survey data. I also have a weight variable, named as "Weight"
      . now I want to display weighted median on chart. The formula I am applying in tableau is "MEDIAN([Variable]). It gives me the median on column bar chart. But I want to display weighted median using the default "Weight" variable of dataset.


      See the screenshot attached. Sorry, have to censor it:)


      Any clues will be highly appreciated.


      MEDIAN.jpgThanks in advance.

        • 1. Re: Median with Weights
          Jim Dehner

          good morning

          Since you did not attach your twbx workbook with the data included I can't give you a specific solution -but conceptually "Median" works at the record level to determine the number of and the value associated with 50% of the marks above (below ) the median - there is another formula - percentile that you can use -

                    Percentile (value,.5) will return the Median BUT the value has to be a disaggregate - you can accomplish that by making your Weighted value a FIXED  lod expression

          Lod expressions return a disaggregated value that can be used in other expressions



          If this posts assists in resolving the question, please mark it helpful or as the 'correct answer' if it resolves the question. This will help other users find the same answer/resolution.  Thank you.

          • 2. Re: Median with Weights
            Milankumar Patel

            Hi Jim,


            Thank you for your reply. Due to restrictions I can’t share the workbook. Is there any alternate way you can suggest?


            I just need to apply weight. We have already a weight variable in our SPSS dataset.


            If you need, I can provide you SPSS syntax script, so you can have an idea how the custom table calculates median.