Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
semgem12
Contributor III
Contributor III

Set Analysis: Last Year Same Week

Hello

Hope someone can help with this please.

I have a table with week numbers and sales for those weeks. The weeks take the format yyww, e.g. 1831 means week 31 of year 2018.

Within a Qlik Sense sheet I want to be able to show each week and the sales for that week as well as the sales for the same week in the previous year. E.g. an entry for 1831 might show

WeekSales for WeekSales Last Year
1831100.0095.00

meaning sales in 1831 were 100.00 and in 1731 they were 95.00.

This is just a sample of the data

LOAD * INLINE [

Week,Sales

1731,95

1732,97

1733,99

1831,100

1832,101

1833,102

etc.

];

So in a table the dimension would be Week and the Sales for Week would be sum(Sales).

I'm not sure how to get the sales for the previous year. I want to be able to do something like

sum({$<Week = {Week-100}>}Sales)

But I know I can't do this.

Can anyone think of a way to do this please?

Thanks.

13 Replies
semgem12
Contributor III
Contributor III
Author

Yes that looks good. Can you tell me how you achieved it please?

menta
Partner - Creator II
Partner - Creator II

Normally if you insert the quote you can search like a text. To verify set analysis I don't insert the name of the expression and in the title i check if the set analysis works properly

sunny_talwar

I attached the qvf with my response above, did you get a chance to open it and check it out?

Re: Set Analysis: Last Year Same Week

semgem12
Contributor III
Contributor III
Author

Thanks Sunny, I didn't spot the attachment. That has worked perfectly, really appreciate it.

For anyone else who might find this useful the script says

Table:
LOAD * INLINE [
Week,Sales
1731,95
1732,97
1733,99
1831,100
1832,101
1833,102
];

AsOfTable:
LOAD DISTINCT Week as AsOfWeek,
  Week,
  'CY' as Flag
Resident Table;

Concatenate (AsOfTable)
LOAD DISTINCT Week as AsOfWeek,
  Week-100 as Week,
  'PY' as Flag
Resident Table;

Within the table/chart the dimension is AsOfWeek and the two measures are

Sales for Week: Sum({<Flag = {'CY'}>}Sales)

Sales for Last Year Same Week: Sum({<Flag = {'PY'}>}Sales)