I´m trying to use your aproach but probably I´m not using it properly, this is the code:

=if(sum({<Fecha={"$(=(Fecha)-364)"}>}Venta6.0) >0, sum(Venta6.0))

What I´m trying to do is to go 364 day before each selected date and see if sales were bigger than zero if that the case sum the selected dates sales (not including sales of the selected dates wich didn´t had any sales 364 days before).

This is very interesting but "Same Store Sales" is a very fundamental measure in the retail space if it were me I would not mess around trying to calculate it in a chart. If you put a Same store sales flag in your fact table then you could multiply the sales amounts by the flag and get the appropriate total.

So I assume on your fact table you have store and data of sale so if you add the store open date you can then evaluate the difference between the Date of sale and the Open Date and set the flag based on whatever threshold is appropriate.

if I wouldn't trust that the calculations in the chart are as accurate as in the script in principle, I think I could stop working with QlikView. Currently we are just throwing in some ideas how to get the things done, I believe nobody wants to get into production without a thorough V&V.

I also prefer a more simple solution over a more complex one, so if SSS is all about the store opening date, Chris' suggestion using just the opening (or first selling date) is probably a good idea. I was assuming that we need to take the Sales comparision with 52 weeks back as given requirement.

Camilo, if you still need the comparison with the sales amount 52 weeks back for any given date, I worked out a solution, please find attached.

I corrected the expression (Look at the expression in the text box, I changed the search expression to a literal, not sure yet why the first has not worked.

So, if you select a single date in the bottom left, you should get the correct result in the text box next to it (for a single selected date).

But I assume you need a date range (like in a chart or table). I think that is problematic with the current solution, because the date as dimension conflicts with the date used in the set expression.

To work around this, I created a separate date field in the script, just as timeline for the tabe/graph. Please look at the second tab in the attached application.

Having the separate time line, you can use simple if-statements to check for past sales and filter the data accordingly.

In deed I need date ranges, I think you are very close on your aproach using an auxiliary date, but I´m using pivot tables and when I transform your Straight Table to a Pivot one a got discrepancies on the agregated data.

Yes Chris I already did what you say using the open date and using something like (Open Date <= Date-364) but at least here SSS is based on a day to day basis, If I just use the open date I will be taking into account those days that didn´t had any sales last year.

Well, if the 52 weeks are a fixed parameter, I guess we could really use a flag in the script.

It would be a bit more complicated than a simple StoreOpenDate, we have to calculate the Sales sums per Store and Date, check for any given Date the sums 52 weeks back and there we go, maybe like this:

SSSSales:

LOAD Date as Date,

Local,

Local &'-'& num(Date) as LocalDate,

sum(Sales) as SumSales

resident Input group by Local, Date;

SSSDates:

left join (Input) Load Date, Local,

if (Lookup('SumSales','LocalDate',Local&'-'&num(Date-364),'SSSSales')>0, 1) as SSS

Resident SSSSales;

drop table SSSSales;

Please have a look at attached sample, I added a second store too ensure we got the SSS correct per Store (look at the demo date in load script, only 31.8./1.9.2010 differing).

I´m trying to get a better understanding of how this work doing somehing similar to another model wich has only years and months (in number format and separate fields). I´m trying to create a sss, but y got a script error sayin that it has an Invalid expression.

Do you know what could be wrong?

SSSSales:

LOAD AñoMes as AñoMes,

Año,

Mes,

Local,

Local &'-'& num(AñoMes) as LocalDate,

sum(Real) as SumSales

resident Data group by Local, AñoMes;

SSSDates:

left join (Data) Load AñoMes, Local,

if (Lookup('SumSales','LocalDate',Local&'-'&(Año-1)&'-'&(Mes),'SSSSales')>0, 1) as SSS

if you use group by, you can only use fields stated in the group by clause as stand alone fields in the load, so in your example, Ano and Mes are not allowed standalone. You could use them in an aggregation function, though.

Mmm I added Mes and Año to de group clause but nothing happen, if I dont have a Date but Year (2008, 2009, 2010... etc) and month (1, 2, 3... 12) only, how should I write the script? I´m trying something like: