5 Replies Latest reply on Mar 29, 2016 11:51 AM by Łukasz Majewski

# Compare two periods

Hi All,

I'd like to know from the experts how to compare two periods.

Let's say something like:

if [SALES] in period 1 > [SALES] in period 2 then "yes" else no

For "Period" I currently use a fortnight calculated as below:

'day',

13-(DATEDIFF('day', #21/9/2014#, [Shift_Date]) % 14),

DATETRUNC('day', [Shift_Date]))

Any help will be much appreciated.

Mattia

• ###### 1. Re: Compare two periods

Hi,

It is absolutely possible but strongly depends on your data and the level of aggregation you use in your view.

If you only have that period in rows as the only dimension used then you could use a calculation like

```LOOKUP(MIN([Sales]),-1)
```

to reference previous period

Please consider sharing a sample twbx so that we can help more

• ###### 2. Re: Compare two periods

Howdy Matia,

I've attached a link to a blog post I've recently written on this very subject. It should show multiple ways of comparing two periods and the workbook will show you how I've then took values from both periods and compared them to see a change/growth/which is bigger.

Cheers!

Carl Slifer

InterWorks

• ###### 3. Re: Compare two periods

Howdy Carl,

I had a look at your solution - pretty neat. If you add 'latest available period in data' option it would be more general and dynamic. One thing to note is that this method  does not allow to partition or filter the data in the view by date periods and only one period can be analyzed/presented.

Cheers,

Łukasz

• ###### 4. Re: Compare two periods

Hi all,

thank you for your suggestions; unfortunately I'm still here with my unsolved calc.

I've attached an extract of the data.

All I'm trying to do is:

-    using [VIC WORKED Undertime cycle hours] I'd like to compare the last two fortnight end date periods

-    in the viz I'll just have a symbol (arrow up or Arrow down)

-    if the latest fortnight end date has a sum([VIC WORKED Undertime cycle hours]) > than the previous period then "up" else "down"

Hope this helps a bit,

Many thanks for the great support.

Mattia

• ###### 5. Re: Compare two periods

this calculation - the measure you want to compare - poses a problem since the LoD expression is { include:} and when [Fortnight end date] is pull into the view it always yields 0:

I do not know what the measure is about but if it was {FIXED:} - what would it be?