3 Replies Latest reply: Apr 8, 2017 6:57 AM by Sunny Talwar

# Calculate Sum of X on a date and Y on a date N days earlier

I'm trying to create a chart that shows a bar for Sum(x) on a date, a bar for Sum(y) on (date-3), and date is the dimension.

So for example, how could I produce a chart that has the following dimensions/measures:

1/5/20171/6/20171/7/20171/8/20171/9/2017
Sum(x) on 1/5Sum(x) on 1/6Sum(x) on 1/7Sum(x) on 1/8Sum(x) on 1/9
Sum(y) on 1/2Sum(y) on 1/3Sum(y) on 1/4Sum(y) on 1/5Sum(y) on 1/6

The source data is one table with a bunch of different dimensions that the user should be able to filter by:

DateDimension 1Dimension 2Dimension Nxy
1/1/2017AC...12
1/2/2017BD...34
...............

My first thought was to use Set Analysis, but after hours of searching, I'm not sure if this is possible.

Does anyone know of any way to accomplish this using any method?

Basically I'd want something like this:

Sum(x)

Sum({<Date={Date-3}>}y)

So that the bar of Sum(y) from the date 1/2/2017 is shown above the date 1/5/2017.

Thanks!

• ###### Re: Calculate Sum of X on a date and Y on a date N days earlier

I would either use the The As-Of Table or something like this

Sum(x)

Above(Sum(y), 3)

or this

Above(Sum({<Date>} y), 3) * Avg(1)

• ###### Re: Calculate Sum of X on a date and Y on a date N days earlier

Thank you, this puts me way closer to the solution I'm looking for. This seems to work while Date is the dimension. Is there a way to make this work so that a weekly or monthly view also produces the same values?

For example:

The bar for Sum(x) over Febuary 2017 should be Sum(x) from 2/1 - 2/28

The bar for Sum(y) over February 2017 should be Sum(y) from 1/29 - 2/25.

What I've tried is: Below(Sum(Aggr(Sum(y), Date)), -3)

But when I switch from Date to Month, the bar shows from 3 months ago instead of 3 days ago.

I feel like I'm confusing the order things take place in or what the functions Aggr/Below are actually doing. I expect Aggr to produce a virtual table at the date level, and Below to operate on that, but it's still operating on the displayed dimension or the actual table.

• ###### Re: Calculate Sum of X on a date and Y on a date N days earlier

May be try something like this

Sum(Aggr(Below(Sum(y), -3), (Date, (Numeric, desc))))

or

Sum(Aggr(Above(Sum(y), -3), (Date, (Numeric))))