Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

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;

View solution in original post

3 Replies
brunobertels
Master
Master

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)

Anonymous
Not applicable
Author

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

Anonymous
Not applicable
Author

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;