Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

wim_embrechts
New Contributor III

Previous week based on today

Hi,

I have a document where I want to display the sales figures of previous week.

Example: If today is week 46, then I want to display only the sales of week 45. I don't want the weeks before week 45 displayed.

Can anyone assist on how to write this in the script because after two days I don't seem to find the right way...

The idea is creating a new dimension PreviousWeek which will only display the data for week(Today())-1.

I added an example file.

Many thanks for your assistance

Wim

Tags (1)
1 Solution

Accepted Solutions
wim_embrechts
New Contributor III

Re: Previous week based on today

solved with adding some new code with preceding load which is fantastic!

CheckPreviousWeekFlag:

load

*,

    week(Datum)-1 as PreviousWeekNew

    where CheckFlagPreviousWeek = 1;

   

load

*,

    if(week(Datum) = week(today())-1,1,0) as CheckFlagPreviousWeek;

3 Replies
brunobertels
Valued Contributor

Re: Previous week based on today

Hi

Depending of your example and the table you provide

If you want a dimension

add this in your sript :

weekname(Datum)-1 as Previous_Week

In your table :

add this mesure

above(sum(sales)

wim_embrechts
New Contributor III

Re: Previous week based on today

Hi Bruno,

Thanks for the information!

It's not exactly the expected result.

1) It's displaying all the weeks instead of one week. I just want one line displayed: Week 45: sum(sales)

2) It's displaying the (last week of the year -1) instead of (current week (46) -1)

3) the totals aren't equal

20171115.JPG

wim_embrechts
New Contributor III

Re: Previous week based on today

solved with adding some new code with preceding load which is fantastic!

CheckPreviousWeekFlag:

load

*,

    week(Datum)-1 as PreviousWeekNew

    where CheckFlagPreviousWeek = 1;

   

load

*,

    if(week(Datum) = week(today())-1,1,0) as CheckFlagPreviousWeek;