Search code examples
tableau-apicalculated-fieldcumulative-sum

Want to visualize a cumulative value of a quotient of two variables from the beginning in Tableau


I'm looking forward to create a parameter or calculation in Tableau that allows me to get a kind of running total of a quotient of two variables.

Let's explain this with a simple example using baseball jargon:

Let's consider that a batter starts a season registering both At Bats (AB) and Hits (H). The Batting Average (BA) is defined as H/AB. All these values are available in my data set on a game basis (each row of the dataset is a game).

I need to calculate the cumulative Batting Average of the batter since it started to play.

The following table/image shows how this can be done in Excel adding some other columns, but I want to create that directly in Tableau using a calculation.

Example data in Excel

Both averages (by game and cumulative) in a Excel graph


Solution

  • You can use RUNNING_SUM on At bats and Hits. And then divide [hits] / [at bats].

    See attached: https://dl.dropboxusercontent.com/u/60455118/160716%20stack%20question.twbx