tableau - calculated field for month can't sum up when trying for quarter -



i'm trying calculate quarterly returns compound.
formula:-
(1+m1)*(1+m2)*...*(1+mn)-1
m1 = first month returns.
m2 = second month returns.

now, didn't find can achieve this. did miss here?
so, created 2 calculated fields [m-1], [m-2] have previous month's returns

([m-1] = lookup(attr([monthly return]), -1), [m-2] = lookup(attr([monthly return]), -2)) 

and calculating new field qr formula:

if(attr([month]) = 3 or attr([month]) = 6 or attr([month]) = 9 or attr([month]) = 12)     ((1+attr([monthly return]))*(1+[m-1])*(1+[m-2]))-1 else     0 end 

this gives me enter image description here

which correct far. when try quarter, should sum 3 month's values , give me q1 right? instead gives me 0 or null below:

enter image description here

can find tbwx file in here. why happening? there missed? there other approach can achieve this?

thanks in advance.

thing is, table calculations (lookup example) depends on level of aggregation explicit on worksheet.

take look, in [m-1] , [m-2] calculation tell tableau want performed on months. in quarter example, taking last quarter values, not months. , using attr, may have unpredictable results when not values each dimension same.

what think happening: attr([month]) not returning 3, 6, 9 or 12 of quarters (i guess tableau take first value, therefore 1, 4, 7, 10), , therefore falls on else 0 loop.

edit: can done? if first chart correct, can hide unnecessary fields. 1 way hiding months you're not interested in. other way more pragmatic, little hack.

create field ([filter months]):

lookup(max([month]),0)%3 = 0 

and drag filters, , select true values

this keep months interested in (multiples of 3), won't screw calculation, because table calculations (like lookup) performed @ last, after calculated. therefore, filtered months won't appear in chart, still considered in other calculations.

you still need keep [month] dimension on chart, can play font size , color hide it


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -