4 Replies Latest reply on May 23, 2016 2:30 PM by Darren Vermaak

    Tableau Noob. Need help on relationships.

    Darren Vermaak

      Hello all,

      I recently switched from PowerBI to Tableau and am running into an issue with relationships.

      I have 3 tables from excel that have been imported into Tableau. They are: StoreDetails (a store list), Store Hours (named Hours), Store Injuries (named LossRun).

      The "primary key" is the store number off the Store List. Store Hours contains multiple entries of the same store number, as does store injuries, but on the store list, there's only 1 store number per every store. So basically just a simple one to many relationship.

      I need to connect all three tables here. In powerBI, i'd take the store number from the store list, and get the count of injuries per store from the store injuries and the sum of hours per store from the store hours table. However, in Tableau, I'm getting incorrect values when I try to do this. I assume it's because I've set up my relationships incorrectly.How would you do this correctly? I assume it's fairly simple, but like I said, I am a Tableau noob.

       

       

      Is the way I've set it up correct?

        • 1. Re: Tableau Noob. Need help on relationships.
          Tom W

          It's hard to provide much insight without further information - "I'm getting incorrect values when I try to do this" isn't enough to go of! Why is it wrong? It it higher? Is it lower? Does it seem duplicated?

           

          Firstly (not having a dig at you!) do you understand what the different join types mean? You're performing inner joins there which means any records from the StoreDetails table which don't have corresponding values in the Hours and LossRun table won't be shown.

          Take a look at this very helpful reference and explanation (you can skip the SQL examples and just read the description - Visual Representation of SQL Joins - CodeProject

          • 2. Re: Tableau Noob. Need help on relationships.
            Darren Vermaak

            No worries.

            I am fairly familiar with joins. Basically the store List contains an entry for EVERY STORE, while store injuries and store hours will likely not include every store. So an inner join would be correct?

            So when store list is just joined with just Store Injuries, I get the correct values when I count the injuries per store:

             

            When I try and set up Store List to be joined by both Hours and Injuries, i get an incorrect value that is significantly higher:

            • 3. Re: Tableau Noob. Need help on relationships.
              Tom W

              Darren Vermaak wrote:

               

              No worries.

              I am fairly familiar with joins. Basically the store List contains an entry for EVERY STORE, while store injuries and store hours will likely not include every store. So an inner join would be correct?

              'Correct' depends on the result you want. To quote the link I used earlier, but changed to suit your scenario - "This query will return all of the records in the left table (StoreDetails) that have a matching record in the right table (Hours).".

              If you have a Store in the StoreDetails which doesn't have a record in the hours table, it's going to be dropped from the result set.

               

              However, this isn't the actual cause of your problem, but it will most likely contribute to your results being off. You need to take a read of this to address your core problem - Removing Duplicated Data after Joining Tables | Tableau Software

              • 4. Re: Tableau Noob. Need help on relationships.
                Darren Vermaak

                Thank you this is what I was looking for.

                I was trying to model my data like I would in Power Bi where I set up all relationships at once. When I follow the data blending technique in the article I get the desired result.