Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
spividori
Specialist
Specialist

Compare data range II

Hi.

I am sorry to republish this discussion, but i need can be done with set analysis because the first items not taken the previous 5 values.

In the attached example, I need to calculate for each day of the dimension five days back and compare them with five days previous to the first 5.

For example, for the day 30/09 day should add 30,29,28,27,26 / 09 and compare them with the days 25,24,23,22,21 / 09.

In the example there are more clarification.

Compare date range

Regards.

Labels (1)
1 Solution

Accepted Solutions
sunny_talwar
MVP
MVP

Try a script like this:

Table:

LOAD Fecha,

     Imp,

     month(Fecha) as Mes

FROM

RangoFechas.xls

(biff, embedded labels, table is Sheet1$);

FinalTable:

LOAD *,

  [5d] - [5d ant] as diff;

LOAD *,

  RangeSum(Imp, Peek('Imp'), Peek('Imp', -2), Peek('Imp', -3), Peek('Imp', -4)) as [5d],

  RangeSum(Peek('Imp', -5), Peek('Imp', -6), Peek('Imp', -7), Peek('Imp', -8), Peek('Imp', -9)) as [5d ant]

Resident Table

Order By Fecha;

Drop Table Table;

Output in Table box object:

Capture.PNG

View solution in original post

10 Replies
sunny_talwar
MVP
MVP

I don't understand the issue? I though it was doing what you wanted? What is missing still?

spividori
Specialist
Specialist
Author

The problem is that when I apply in my application with the longer period the first values do not take the previous 5.

Regards.

Capture1.PNG

sunny_talwar
MVP
MVP

May be a condition on all your expressions:

If(RangeSum(Above(Sum(Imp), 5, 5)) > 0, YourExpression)

sunny_talwar
MVP
MVP

Try this instead:

If(Above(Sum (Imp), 9) > 0, yourExpression)

Capture.PNG !

spividori
Specialist
Specialist
Author

I added more data to the example and when I select Sept. it shows data from the 10/09 and I need to show the whole month.

Regards.

Capture1.PNG

sunny_talwar
MVP
MVP

See attached:

Capture.PNG

spividori
Specialist
Specialist
Author

See that there is dates not calculated.

01,08,15,22 y 29.

Regards.

sunny_talwar
MVP
MVP

Check this out:

Capture.PNG

Would a script based solution work for you also?

sunny_talwar
MVP
MVP

Try a script like this:

Table:

LOAD Fecha,

     Imp,

     month(Fecha) as Mes

FROM

RangoFechas.xls

(biff, embedded labels, table is Sheet1$);

FinalTable:

LOAD *,

  [5d] - [5d ant] as diff;

LOAD *,

  RangeSum(Imp, Peek('Imp'), Peek('Imp', -2), Peek('Imp', -3), Peek('Imp', -4)) as [5d],

  RangeSum(Peek('Imp', -5), Peek('Imp', -6), Peek('Imp', -7), Peek('Imp', -8), Peek('Imp', -9)) as [5d ant]

Resident Table

Order By Fecha;

Drop Table Table;

Output in Table box object:

Capture.PNG