6 Replies Latest reply on Apr 19, 2018 8:00 PM by Jesus Fandino

# Create a correct calculated field

Hello Tableau Community.

I'm new to Tableau and I'm working hard trying to figure out a number of things. I have a dataset of ATP matches (tennis) from 2000 to 2005. It contains a number of columns, including tourney_id, tourney_name, tourney_date, winner_name, loser_name,  etc. Each row represents a tennis match and the columns provide the context for it. I was able to accurately calculate the number of wins for each of all players in the given period by creating a calculated field (I'm working in parallel using python, so I'm sure whenever I have the correct answers). The same for the number of loses. What I find nonintuitive is to create a field for the number of matches played in that period for each tennis player.  (It should be as easy as to add both of the previously created fields, but my problem is that I do not have at this moment a single field for player names, I have two instead, one for losers and another for winners), this task should be easy, I just don't know how to proceed. Any help will be much appreciated.

• ###### 1. Re: Create a correct calculated field

HI Jesus

On your case with Tableau, you'd better duplicate your data to get Names both for winner and loser.

You can use Union.

Thanks,

Shin

1 of 1 people found this helpful
• ###### 2. Re: Create a correct calculated field

Hi Shinichiro!

Your solution was absolutely clever! Thank you for your help. That, of course, answers my question, however before closing this thread, I'm wondering how to build on top of that. Let say that I'm interested in visualizing the %of wins, (that was what I had in mind when I wrote this post ) instead of wins and losses. That is going to be a single number, which is easily calculated as 100 * number of wins /(number of matches). Since the number of matches in your approach is obtained as a result of computing the number of records (if I correctly understood your solution), it is unclear to me how I could use it in a calculated field.

My approach in python was to build a new data frame with player_id as rows and add there all the stats I needed as columns. Does Tableau allow anything like that?

Thank you again for your help

Jesus

• ###### 3. Re: Create a correct calculated field

Hi Jesus

Here you go.

Approach with Tableau in this case is using LOD.

I don't know Python very well, but most of basic calc does not require other coding.

Thanks,

Shin

1 of 1 people found this helpful
• ###### 4. Re: Create a correct calculated field

The sequence of the post is something wrong, but please refer the post before your question.

Shin

1 of 1 people found this helpful
• ###### 5. Re: Create a correct calculated field

Hi Shinichiro!

Thank you very much! It was extremely helpful.

Regards