3 Replies Latest reply on Aug 16, 2018 3:50 AM by Jim Dehner

# Get % change from current week days to the same last week days

Hello Everyone,

i want to get the % change on last week days from Current week.
Days       Like last sales        Current week sales      % change

Monday       200                         400                          50%+
Tuesday      100                         70                            30 %-

So i have got sales numbers for last week and current week by doing below calcs

_Max Date
{ FIXED DATEPART('year', [Order Date]),DATEPART('month', [Order Date]) : MAX([Order Date])}

_Previous Week Day

DATE([_Max Date]-7)

_Prior Week Day

DATE([_Previous Week Day]-7)

_current Week Sales

IF [Order Date]>=[_Max Date]-7

THEN

[Sales]

END

_Previous Week Sales

IF [Order Date]>= [_Prior Week Day] AND [Order Date]<= [_Previous Week Day]

THEN

[Sales]

END

This is how my view looks Like

After little cleaning up this is how it looks

But when I want to get difference between current wk sales - previous week sales then I get 0, I don't know what I am doing wrong
This is my calculation for difference

_week Diff

{ FIXED DATEPART('year', [Order Date]),DATEPART('month', [Order Date]): SUM([_Previous Week Sales]-[_current Week Sales] )}
or

[_Previous Week Sales]-[_current Week Sales]

can anyone help me ? I have attached my workbook it's based on sample superstore.

Tableau Version : 2018.2

• ###### 1. Re: Get % change from current week days to the same last week days

Good morning

see the attached

try this

it returns this

1 of 1 people found this helpful
• ###### 2. Re: Get % change from current week days to the same last week days

Thanks a lot Jim, but can you explain why I have to wrap every calculation in SUM() function? I still don't know tableau so much.

• ###### 3. Re: Get % change from current week days to the same last week days

When you bring measures to the canvas they are aggregated - (i.e. after filters are applied the values the remain (by dimension) are aggregated -

your values for current and previous week sales are disaggregated and will be aggregated as you bring them to the viz   - that is equivalent to doing the percent calculation at the record level then aggregate individual results when you bring it to the vis - rather than summing the individual values and then determining the percent