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

Same Weekday same Week Last Year as part of a range covering last 7 days

Hi

I have a straight table with the following Dimension which displays data for the previous 7 days. varViewDate simply sets the "current date" of the data to look at:

=Date(if(Date>=($(varViewDate)-7) and Date<=($(varViewDate)-1), Date),'DD/MM/YYYY')

And expressions to display the corresponding revenue and budget for each of those days. These exclude any date fields from the expression so they only ever show the last 7 days:

=ONLY({$<Year=,Quarter=,Month=,Week=,Day=,Date={'>=$(=(varViewDate)-7)<=$(=(varViewDate)-1)'}>}Revenue)

=ONLY({$<Year=,Quarter=,Month=,Week=,Day=,Date={'>=$(=(varViewDate)-7)<=$(=(varViewDate)-1)'}>}RevBudget)

This all works correctly so far.

What I now want to do is display the data for the "same day" last year. "Same day" is the same day of the week in the same week of the year last year, across the range for the previous 7 days. For example Thursday 2nd June 2016 corresponds to Thursday 28th May 2015. Shown here as column "2015".

Straight table L4L.png

In a text box, the formula below displays the correct date last year. Changing the number 7 correctly modifies how many days before the "current day last year" is displayed:

=Date ( MakeWeekDate ( Year($(varViewDate))-1 , week($(varViewDate)-7) , weekday($(varViewDate)-7)) , 'DD/MM/YYYY' )

This needs to be incorporated in Set Analysis. I've tried many expressions, none of which display any data, I only get the Null() "-" character:

=ONLY({$<

Year=,Quarter=,Month=,Week=,Day=,Date=

{'

>= $(=Date ( Makeweekdate (

Year($(varViewDate))-1 , Week($(varViewDate)-7) , Weekday($(varViewDate)-7)

)))

<= $(=Date ( Makeweekdate (

Year($(varViewDate))-1 , Week($(varViewDate)-1) , Weekday($(varViewDate)-1)

)))

'}

>} Revenue )

I've also created a variable called SameDayLastYear and tried using that instead of the Makedate function, but without any joy.

I'm tempted to create a field in the load script to calculate the date, but hardcoding the dates for the previous year doesn’t work either:

=ONLY({$<Year=,Quarter=,Month=,Week=,Day=,Date={'>=$(=Date(42146))<=$(=Date(42152))'}>}Revenue)

I've seen similar examples on the community site which suggests this is possible. Working through other examples such as the following, I can't see why this doesn't work.

https://community.qlik.com/docs/DOC-9162

https://community.qlik.com/message/793168#793168

https://community.qlik.com/message/13511#13511

Help greatly appreciated.

Thanks

Ian

11 Replies
New-Qlik
Creator II
Creator II

Hello Sunny , 

 

I tried your solution n its worked nicely for TY week but for LY it works  like this 

Sales TYSales  LYSales Order Purchase Date
003/13/2019
003/14/2019
003/15/2019
003/16/2019
003/17/2019
003/18/2019
003/19/2019
89-3/11/2020
67-3/12/2020
78-3/13/2020
38-3/14/2020
22-3/15/2020
31-3/16/2020
34-3/17/2020

 

n if i remove below condition  from LY its like this 

Sales  TYSales - LY Date
0143/13/2019
0113/14/2019
0943/15/2019
0163/16/2019
0233/17/2019
0113/18/2019
0123/19/2019
8903/11/2020
6703/12/2020
7803/13/2020
3803/14/2020
2203/15/2020
3103/16/2020
3403/17/2020

    

Can you help.i used this expression

sum({< Date = {">=$(=MakeWeekDate(Year(today())-1, Week(today()-7), WeekDay(today()-7)))<=$(=MakeWeekDate(Year(today())-1, Week(today()-1), WeekDay(today()-1)))"}>}[Sales])

 

New-Qlik
Creator II
Creator II

@sunny_talwar  Kindly suggest.