4 Replies Latest reply on Oct 23, 2019 5:27 PM by Hari Ankem

# Trying to calculate correct # of innings pitched for baseball

Hello,

I am looking for some help on my simple problem.   I am trying to calculate ERA for a set of pitchers w/in Tableau.

In baseball P get credit for innings in 1/3.  So if a P pitches into the 2nd inning but gets only 2 outs in that inning he has pitched 2 2/3 innings, or 2.6667 in decimal format.

In my csv file i have a 3 fields (Full Innings Pitched, Partial Innings Pitched, Total Innings Pitched)

Partial Innings Pitched in my csv has values of either (0, .3333 or .6667)  - this way if i add these #s up they will round up to a whole #  100.3333 + 100.6667 = 201.0 Innings P

Simple enough.

Problem # 1 - When i look at the data when its ingested into Tableau it now shows up like below.

Its truncating and rounding the data to 2 or 3 decimal places (down from the 4 places in the CSV file) which i believe is causing issues with my calculations later on.

.6667 in the CSV becomes .67 and .667 in Tableau

.3333 in the CSV becomes .33 and .333 in Tableau

The source CSV is formatted this way.  You can see the values all have 4 places after the decimal point.  This is the format that i want it to be in when it gets into Tableau.

You can see that now my decimals are not .3333 or .6667 in import (i have .9998 and .0001 and .3334, etc values) showing up on my graph.

Can i change the format of the data in the DataSource field?  If not how do i change the measures of those fields in Tableau to be 4 decimal places again?  I need to get my measures back to 4 decimal spots for proper additions to work.

2nd part of my question if we can fix the above so my calculations work correctly.  My output will be 3 results for Total Innings Pitched:

1) Whole # = 100

2) 1/3 inning = 100.3333

3) 2/3 inning = 100.6667

Is there way with Tableau to say if the value contains .3333 then display 100.1 and if the value contains 100.6667 then display 100.2

Thanks in advanced for the help

~Mike

• ###### 1. Re: Trying to calculate correct # of innings pitched for baseball

Set the default number format for the measure as shown below:

You should then see the data as required.

• ###### 2. Re: Trying to calculate correct # of innings pitched for baseball

OK that seemed to have fixed that issue of it truncating digits.  But it looks as if Tabeleu still can't figure out how to handle innings or a number as a fraction.

I just did a test and it looks like i have a pitcher over 3 seasons that pitched 100.3333 innings per season - what it should be is 100.3333 + 100.3333 + 1000.3333 = 301.0 innings.  But what is showing up is 300.9999 innings.

Can tableau do fractional math?  Is there a function for that like in excel ?  If not perhaps i need to format the data before it gets into tableau?

• ###### 3. Re: Trying to calculate correct # of innings pitched for baseball

Just thinking more -- even if i do get it to .1 .2 in excel when in import into Tableau - it needs to know that this is a fraction of a number.  Maybe another something with my formula? when getting the sum of all innings?

• ###### 4. Re: Trying to calculate correct # of innings pitched for baseball

We can create calculated fields to display 100.1 in lieu of 100.3333. If you can provide your packaged workbook (.twbx) and let me know your exact requirements on it, I can probably help.