Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Qlikview script where condition

Hi,

I would like to select last 20 weeks from my base data using where /match condition. I have a field Week_ID, ranges between 1 to 52 for an year. I want select latest 20 weeks. I am trying to write something below. but getting error:

where Count(WEEK_ID)<=52 order by WEEK_ID desc;

Regards, please suggest.

1 Solution

Accepted Solutions
maxgro
MVP
MVP



source:

load *inline [

Week, Sales

1, 100

2, 90

3, 80

4, 110

5, 120

6, 90

7, 80

];

max: load max(Week) as MaxWeek Resident source;

let vMaxWeek=peek('MaxWeek');

final: NoConcatenate load * Resident source where Week >= $(vMaxWeek)-2;

DROP Table source;

View solution in original post

16 Replies
maxgro
MVP
MVP

WEEK_ID > 32

Not applicable
Author

Try this.... WHERE WEEK_ID > 32 ORDER BY WEEK_ID desc;

sunny_talwar

Just need to use


Where WEEK_ID >= 33;

I am not sure why you need to order WEEK_ID, unless you want to do it for some other reason not mentioned here.

HTH

Best,

S

Anonymous
Not applicable
Author

if your WEEK_ID is the number of the week, you don't need count() function and for that matter why do you need to check if it is <= 52?

to select the last 20 weeks, you need something like below:

data1:

Load *

from /*your table*/

Order by WEEK_ID desc;

data2:

noconcatenate First 20 //this selects the latest 20 weeks

load * resident data1;


drop table data1;

Not applicable
Author

Hi, the issue is not resolved. Let me restructure it.

Suppose this is the data, how can I upload only last 3 weeks data in QVW?

WeekSales
1100
290
380
4110
5120
690
780


Thanks!

Colin-Albert

First 20 will load the first 20 rows of data.

This is unlikely to be the last 20 weeks of data!

Not applicable
Author

Good point I need last 3 weeks , not last 3 rows


Anonymous
Not applicable
Author

Indeed.  It will work correctly only if each data row represents exactly one week.

It is safer to have Date in the data (it could be a week start for example), so it can be compared with date(today() - 7 * 20)

sunny_talwar

Two ways:

Method 1:

Table:

LOAD * INLINE [

    Week, Sales

    1, 100

    2, 90

    3, 80

    4, 110

    5, 120

    6, 90

    7, 80

];

Table1:

NoConcatenate

LOAD *

Resident Table

Where Week >= 5;

DROP Table Table;

Method 2:

Table:

LOAD * INLINE [

    Week, Sales

    1, 100

    2, 90

    3, 80

    4, 110

    5, 120

    6, 90

    7, 80

];

Table1:

NoConcatenate

First 3

LOAD *

Resident Table

Order By Week desc;

DROP Table Table;

HTH

Best,

S