7 Replies Latest reply on Feb 26, 2016 11:32 AM by Ben Page

# Creating calculated field for Year-to-date values

Hello,

I have a very simple graph as shown below.

What I would like to do is add a line, or another bar next to it that shows Year to date values.

For example, this new bar on January would be identical to the existing one. For February, it would show January + February values, so its bar would be longer.

March would be January + February + March, and so on.

How can I achieve this in calculated field??

I attached a slightly different workbook for example, but same logic.

• ###### 1. Re: Creating calculated field for Year-to-date values

hi Roy,

If I've understood your requirement correctly the answer is very easily!

Tableau has a built in 'short-cut' for running-sum

This is a Table Calc (you can see the formula it creates by double clicking the Green Pill), and you can also tell it's now a Table Calc as the Green Pill now has a little triangle on the left)

Hope this is what you were after, but if not please post back

• ###### 2. Re: Creating calculated field for Year-to-date values

Simon is right that you can use Tableau's running sum to give you your YTD values, given your data. If you plan to show multiple years of data then you might need to take a different approach. I've created a workbook that shows both side by side bars as well as a line over a bar chart. You simply use your "Value" field as well as the Value field with a Running sum calc attached to it like Simon alluded to.

Attached is my workbook, let me know if this helps.

Ben

• ###### 3. Re: Creating calculated field for Year-to-date values

Thanks!!

• ###### 4. Re: Creating calculated field for Year-to-date values

Hi Ben,

That's perfect. One question, though. I opened your workbook and it doesn't seem like there's a new Measure created called "Running Sum Value" but you are able to add it on top of the existing Sum(Value).

How can this be done? I am sorry for such elementary question but I would like to know how you were able to use one measure (Value) to populate two bars.

• ###### 5. Re: Creating calculated field for Year-to-date values

You can bring the same measure into a view as many times as you want. To test, simply drag "Value" onto the row shelf more than once. For "Measure Values," it's a little trickier. You cannot add the same measure to "Measure Values" more than once. However, once you modify your measure with a table calc (like running sum), Tableau treats it like a different measure, and will allow you to add the original measure to "Measure Values." Does this make sense?

• ###### 6. Re: Creating calculated field for Year-to-date values

Yes, thank you!

One last question ( I promise )

If I wanted that second Year to date columns to only appear for, let's say February through October, how could I limit it?

• ###### 7. Re: Creating calculated field for Year-to-date values

You can filter out months you don't want using a couple of methods. Selecting your range, right-clicking and selecting " Keep Only" is one of them.