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

Best way to do YTD data current week Vs same week last year

Hi,

I want to show YTD data current week Vs same week last year, everyone has examples to do it in months. 

And how do i display it in a table week per week per row, so we will have 32 rows this week and 33 next week etc.

Thanks

1 Solution

Accepted Solutions
maximiliano_vel
Partner - Creator III
Partner - Creator III

Is this what you looking for?

View solution in original post

16 Replies
Anonymous
Not applicable
Author

No replies yet, I'm glad it's harder than i thought.

rubenmarin

Hi manraj, if you have a master calendar you can use week number as dimension.

Then you can create two expressions, one for current year and one for last.

Sum({<Year={'$(=Max(Year))', Date={'<=$(=Date(Today()))'}>} Value)

Sum({<Year={'$(=Max(Year)-1)'}, Date={'<=$(=Date(AddYears(Today(), -1)))'}>} Value)

sorrakis01
Specialist
Specialist

Hi,

Are you using Master Calendar?

Anonymous
Not applicable
Author

I've tried week number as the Dimension, but because i got 2014 in one of the columns, the weeks go down to 52, i want it to stop at current week on the straight table, for example, this week will have 32 rows and my totals will show week 32 2015 totals v week 32 2014 totals.

Anonymous
Not applicable
Author

No

maximiliano_vel
Partner - Creator III
Partner - Creator III

To Create a Master Calendar

LET vCalendarMinDate = Num(MakeDate(2014,1,1)); //Change accordingly with your data

LET vCalendarMaxDate = Num(MakeDate(2014,8,4)); //Change accordingly with your data

Calendar:

LOAD Date,

     Year(Date) as Year,

     Month(Date) as Month,

     Day(Date) as [Day],

     Week(Date) as [Week]

     //Any other calendar fields you whish to create

;

LOAD

  $(vCalendarMinDate)+IterNo()-1 as Date //Shoud be the FieldName in your data

AUTOGENERATE 1

WHILE $(vCalendarMinDate)+IterNo()-1<=$(vCalendarMaxDate);

In Settings->Variable Overview create the fallowing variables

Say the maximum date in the master calendar is 04/08/2015 (DD/MM/YYYY)

vMaxDate =Num(Max(Date)) //Should evaluate to 04/08/2015 (DD/MM/YYYY) = 42220

vYear =Year($(vMaxDate))

vLastYear =Year(AddYears($(vMaxDate), -1))

vMaxWeekSameYear =Week($(vMaxDate)) //Should evaluate to 32

vMaxWeekLastYear =Week(AddYears($(vMaxDate), -1)) //Same as Above

For LYTD (Last YTD)

Sum({<Calendar.Year={$(vLastYear)}, Calendar.Week={"<=$(vMaxWeekLastYear)"}>} Value) //This should accumulate the values up to Week 32 of 2014

For YTD

Sum({<Calendar.Year={$(vYear)}, Calendar.Week={"<=$(vMaxWeekSameYear)"}>} Value) //This should accumulate the values up to Week 32 of 2015

jonathandienst
Partner - Champion III
Partner - Champion III

A good data model is designed to support the analysis required by the client. In your case you want to time series analysis. While this can be done without a calendar, it is a lot simpler if you have the requisite calendar fields as required by your users. Usually this is put in a separate master calendar table. There are plenty of links on tjhis site about how to set up a master calendar.

In your case you need a Week field and a Year Field. Then you can use set expressions to select the same week ranges for this year and last year and Week as a dimension in your chart/table:

Define these variables:

Set vMaxWeek = '=Week(Today())';

Set vMaxYear = '=Max(Year)';

Use these expression for CYTD and LYTD by week:

Sum({<Year = {$(=vMaxYear)}, Week = {"<$(=vMaxWeek)"}>} Amount)

Sum({<Year = {$(=vMaxYear - 1)}, Week = {"<$(=vMaxWeek)"}>} Amount)

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Anonymous
Not applicable
Author

I've tried that and it gives similar results in a straight table, it's still calculating all 2014 weeks rather than total of how 2014 was at week 32

Anonymous
Not applicable
Author

I want the rows to stop at week 32 and total up only up to week 32 for 2014

  

Booking Week20152014
     ytd 2015same ytd totals 2014
129358284
2530712769
3533411416
449899789
553978383
649645598
741295329
834745548
934085805
1030226581
1127078030
1227406463
1329285121
1428075418
1529846112
1631905825
1730705853
1830545493
1929696058
2034667176
2137806837
2234415972
2337806223
2432656744
2534408048
26342010050
2737546063
2837956972
2941257246
3040608432
3130587468
3204714
3306047
3407590
3507331
3605691
3704868
3804512
3905314
4003980
4103041
4203167
4303375
4403850
4504741
4603737
4703695
4803025
4902938
5003002
5103252
5202987