Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
keynes
Contributor
Contributor

Calculate Previous Week

Hello,

I have the following expression, which displays data for the current week in a KPI:

Sum({<date={">=$(=Weekstart(max(date)))<=$(=Weekend(max(week_date)))"}>}[Total Customers])

I would like to display the previous weeks figure in the secondary KPI, but I just can't seem to find the right answer. If anybody here can help, I would be extremely grateful. 

Labels (2)
6 Replies
Chanty4u
MVP
MVP

May b this 

Sum({<[ Date] = {'$(=Date(Max([ Date])-7))'}>} customer)

Chanty4u
MVP
MVP

=sum({<date={"=inweek(Date,today(1),-1)"}>} customers)

keynes
Contributor
Contributor
Author

That's along the right lines, but it gives an output which adds up a total of all the customers from all previous weeks.

What I need is to just show the previous weeks figure alone. 

Many thanks for your help.

 

Chanty4u
MVP
MVP

The first one should work but try below

Something like this

 

sum({<OrderDate={">=$(=Date(today()-7,'MM/DD/YYYY'))<=$(=Date(today(),'MM/DD/YYYY'))"}>}Sales)

 

 

 

Change the Date format 'MM/DD/YYYY' to whatever format you have in OrderDate

keynes
Contributor
Contributor
Author

Hi @Chanty4u - your help has got me closer to a solution, but I'm still not quite there. The following code gets me the calculation I want (current week - previous week), but it does not work when any filters are applied. Might you possibly know why this is?

Sum({<date={">=$(=Weekstart(max(date)))<=$(=Weekend(max(week_date)))"}>}[Total Customers])
-
Sum({<date ={">=$(=Weekstart(max(date),-1))<=$(=Weekend(max(date),-1))"},Week=>}[Total Customers])

Chanty4u
MVP
MVP

try more simpler way

create week in your script use like below.

Sum({$<week={$(=Max(week)}[Total cust])_Sum({$<week={$(=Max(week)-1}[Total cust])

 

for your query- try to keep in two kpi objects for two measures and test its working or not.