Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
Qliksense_77
Creator
Creator

Make YTD comparison with only a year-week field

Hi,

How do I make a KPI that compare YTD sales for current and last year, when I only have a date field like below?

Period_typePeriodSales
Week2021W04121
Week2021W03100
Week2021W02120
Week2021W01121
Week2020W53121
Week2020W52111
Week2020W51154
Week2020W50132
Week2020W49121
Week2020W4898
Month2021M01262
Month2020M12188
Month2020M11256
1 Solution

Accepted Solutions
NageshSG
Partner - Contributor III
Partner - Contributor III

Hi @Qliksense_77 ,

Good question! I had added some dummy data for 2020 Wk 1to 4.

See how this works in the attached sample qvw file. Weeks and Months will overlap, hence need to fix the measure in the set expression. Either the Week YTD is enabled or the Month YTD for easy reference.

Also the screen shot below:

NageshSG_0-1631000094403.png

NageshSG_1-1631000388959.png

 

Regards.

View solution in original post

4 Replies
NageshSG
Partner - Contributor III
Partner - Contributor III

Hi @Qliksense_77 

As I understand from the table, the Period_type defines the Period which are in buckets of weeks or months.
Since the 'date' field is rounded off to a week or a month, you can extract out the Year from Period and create a 'Year' field in the script as below:
Please note that the actual underlying calendar transaction date may spill over the 'next/previous year' like for example Week 53/52 or Week 01.

Script side:
Load
Period_type,
Period,
left(Period,4) as Year,
num(right(Period,2)) as Wk_Mth_Number,
Sales
from <data_source>;

Front end / Layout:

You can derive the current YTD / last year YTD (based on the completed weeks/months) as under:
Current Year to Week Sales = Sum({<Period_type={'Week'},Wk_Mth_Number={"<=$(=Max(Wk_Mth_Number))"},Year={$(=Max(Year))}>}Sales)
Previous Year to Week Sales= Sum({<Period_type={'Week'},Wk_Mth_Number={"<=$(=Max(Wk_Mth_Number))"},Year={$(=Max(Year)-1)}>}Sales)
Current Year to Month Sales = Sum({<Period_type={'Month'},Wk_Mth_Number={"<=$(=Max(Wk_Mth_Number))"},Year={$(=Max(Year))}>}Sales)
Previous Year to Month Sales= Sum({<Period_type={'Month'},Wk_Mth_Number={"<=$(=Max(Wk_Mth_Number))"},Year={$(=Max(Year)-1)}>}Sales)

Hope this helps.

Regards.

Qliksense_77
Creator
Creator
Author

Thanks @NageshSG ,

It works for current year. But the expression for last year does not work. The expressions for last year include all weeks/months. You know what the problem can be?

NageshSG
Partner - Contributor III
Partner - Contributor III

Hi @Qliksense_77 ,

Good question! I had added some dummy data for 2020 Wk 1to 4.

See how this works in the attached sample qvw file. Weeks and Months will overlap, hence need to fix the measure in the set expression. Either the Week YTD is enabled or the Month YTD for easy reference.

Also the screen shot below:

NageshSG_0-1631000094403.png

NageshSG_1-1631000388959.png

 

Regards.

Qliksense_77
Creator
Creator
Author

Thanks @NageshSG , 

It works now😊