6 Replies Latest reply on Nov 7, 2017 12:53 AM by Hector Monsalve

    Pie chart based on content from different columns

    Hector Monsalve

      Hi All,

       

      recently in time I have had the need to create a pie chart with certains properties and I am struggling with it.

      I will use an example to explain the expected result.

       

      Let´s say we have a table with different users, and each user has 4 columns: Name, Hobby#1, Hobby#2 and Hobby#3. For example:

      exaple_tableau_rows.PNG

       

        I need to build a pie chart filtered by hobby, where each hobby sums +1 if the hobby appears in any of the Hobby#N column of each user.

        In this example, the pie chart should show:

      • Football > 4
      • Tennis > 3
      • Basketball > 2
      • Bike > 2

        Then when clicking on each Hobby in the pie chart, it should show all users who has this hobby in any of the 3 Hobby#N column.

       

      Could anyone help me with some ideas on how to build it up?

       

      Thanks a lot in advance,

      Hector.

        • 1. Re: Pie chart based on content from different columns
          venkat.ram.1

          Hey Monsalve,

           

          You have you work in excel file or source file like below.

           

           

           

          NameHobby
          JamesTennis
          JamesFootball
          PeterBasketball
          PeterTennis
          PeterFootball
          JosephFootball
          ….. All user and Corresponding Hobbies
          • 2. Re: Pie chart based on content from different columns
            Hector Monsalve

            Hi Venkat,

             

             

            thanks for the quick answer.

             

             

            In the real scenario, I get the info from a data base, and there each user has one unique field Hobby, where all the hobbies come separated by comma.

            On Tableau I break this field into 3 calculated fields: Hobby#1, Hobby#2, Hobby#3.

            So it is not possible to prepare the table in the way you mention on the datasource.

             

             

            Is it the only way to do it?

            Or would it be possible to get what I need managing the data in Tableau directly?

             

             

            Thanks in advance,

            Hector.

            • 3. Re: Pie chart based on content from different columns
              Branden Kornell

              Venkat is correct that your data needs to be reshaped to work with it effectively in Tableau. However, there may be workarounds to get you there.

               

              1. What database are you using? You may be able to split and pivot the data.

              2. Are there a standard group of hobbies, or is it a free-form text field?

              3. How many hobbies total are there?

              • 4. Re: Pie chart based on content from different columns
                venkat.ram.1

                Hey Monsalve,

                 

                I think its little bit complicated, I think there are lot of calculations need to be done.

                 

                May be we need to use String Calculations, I dont think that is a good Idea in creating for each Individual.

                • 5. Re: Pie chart based on content from different columns
                  Alan Perez

                  Are you looking for something similar to this?

                   

                  • 6. Re: Pie chart based on content from different columns
                    Hector Monsalve

                    Hi Alan,

                     

                    thanks all for the answers.

                    What I am looking is something like this:

                     

                    tableau_example.PNG

                     

                    I want to show for each user, all the hobbies, but it seems that it is not possible with the data as it is on the database now.

                    So we will figure out how to prepare the data at the data base level.

                     

                     

                    My problem now, is that each user has a list of hobbies, but one of the hobbies is the Main Hobby.

                     

                    Preparing the data like it was recommended before I have this:

                     

                    tableau_example_data.PNG

                     

                    And the issue, is that I want to make a second Pie Chart representing the different Hobbies, but counting only ONE row per user.

                    I mean, I do not know how to create a calculated field that from the field of the table Main Hobby, counts:

                    • Tennis = 2 (the main hobby for James and Marie)
                    • Football = 2 (the main hobby for Peter and Josehp)
                    • Bike =1 (the main role for Laura)
                    • Boxing = 1 (the main role for Conor)

                     

                    What I get if I use the Number of Records for the Main Hobby column , is:

                     

                    Tennis = 4

                    Football = 4

                    Bike = 1

                    Boxing = 3

                     

                    But I do not want that behavior, I want to count only one entry per user.

                     

                    Could anyone help me with that?

                    Thanks a lot in advance!

                     

                    Hector.