2 Replies Latest reply on Nov 8, 2013 1:41 AM by Gorazd Ozimek

# Inside calculation definition based on measure?

This is a part of my calculation, which chooses a measure based on the combination of two filters, which is joined into [Measure + Time Period String]

CASE [Measure + Time Period string]

WHEN "Sales in LC Monthly" THEN

WINDOW_SUM(SUM([Sales in LC]), 0, 0)

WHEN "Sales in LC R3M" THEN

WINDOW_SUM(SUM([Sales in LC]), -2, 0)

WHEN "Sales in LC R6M" THEN

WINDOW_SUM(SUM([Sales in LC]), -5, 0)

WHEN "Sales in LC MAT" THEN

WINDOW_SUM(SUM([Sales in LC]), -11, 0)

WHEN "Sales in LC YTD" THEN

RUNNING_SUM(SUM([Sales in LC]))

So the calculation is based on choice of the measure - for example Sales in LC R6M is a moving total of last 6 months in local currency sales. Everything is working fine except the YTD figure. That figure should restart the running sum each year which can be defined in the table calculation window shown below (Restarting every Year of Time - Month). The problem is however that if I set this, it also affects other moving total measures which I don't want to. Is it possible to write a code specifically for YTD measure so that it restarts every year?

Thanks,

Gorazd • ###### 1. Re: Inside calculation definition based on measure?

If you create a separate calculation for that part of the case (RUNNING_SUM(SUM([Sales in LC]))) , then refer to this calculation in the case statement, Tableau will give you a dropdown on the table calc dialog that allows you to set different partitioning for each.

1 of 1 people found this helpful
• ###### 2. Re: Inside calculation definition based on measure?

Thanks Alex, your answer was helpful. However I thought that maybe there is an option to do it inside the calculation, which would keep down the number of calculations in my workbook.

Regards,

Gorazd