Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Discover how organizations are unlocking new revenue streams: Watch here
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

A tricky problem that I am facing

I need to draw a graph with a date and 2 expressions.

The table structure is like this and the sample data is like this

YearMonthWeekDaySalesDate
2012-201311-11100011-Jul-12
2012-201311-1130011-Jul-12
2012-201311-1250012-Jul-12
2012-201311-1320013-Jul-12
2013-201411-11250016-Jul-13
2013-201411-11150016-Jul-13
2013-201411-12500017-Jul-13
2013-201411-13250018-Jul-13
My chart should look like this
DateThis YearLast Year
16-Jul-1340001300
17-Jul-135000500
18-Jul-132500200

Should get 4000 based on the 2 records for 16-Jul, and 1300 is derived based on the same month, week and day in the previous year 2012-2013. 11-Jul-12 is the equivalent day in the previous year and the sum 1300 hence. and so on.

I tried something like this for the second expression but it just gives me the same value as the 1st expression.

=Sum( {<[Sale_year]={"=SubField([Sale_year], '-')-1  & '-' & SubField([Sale_year], '-')"} >} [Sales])

Can you kindly advise. The crux of this is the year in the second expression points to the previous years but all the other columns should match. (Month, week and day).

Thanks,

Ram

1 Solution

Accepted Solutions
tresesco
MVP
MVP


PFA. Hope this helps.

View solution in original post

14 Replies
tresesco
MVP
MVP

This is something you have to work in the script for. You have to create an additional field for last year data. As Of Date approach is the one you have to follow. PFA, hope, that would give you an idea.

Not applicable
Author

Thanks treseco. Isn't there any other simple way by which I can manipulate expression to point to a date in the previous year? My case is I need to use some 4 fields to go back and find the equivalent date last year.

sujeetsingh
Master III
Master III

Tresesco,

You just written a to the point script.

Ram just what you have to do is to just maintain months and dates to in the script and you can get what you want.

tresesco
MVP
MVP

I won't say that 'it is impossible' to achieve in the front-end. Probably you can, using complex logic with concat function. But that would be too cumbersome. It is always recommended to use the script way. In qlikview AS Of Date  is much known for the similar requirement and you would find post by John Witherspoon in the community. I would suggest you to go through the same; take the pain once and gain for ever.

Not applicable
Author

Thanks treseco. What you say makes perfect sense. And it worked as expected. But there is still one issue. Once I change the year format from 2013 to '2013-2014', the value under 'Previous' shows the sum of 'Current' and 'Previous'. Not sure why. Can you please look at the attached?

Thanks once again.

regards!

jolivares
Specialist
Specialist

I think that is not "possible" (not necessarily impossible in QV) because you're trying to show results over a different dimension,  If you choose the day it's better:

This Year : Sum(If(Year(Date(Date#(F6,'D-MMM-YY')))=Year(Today()),F5))

Last Year : Sum(If(Year(Date(Date#(F6,'D-MMM-YY')))=Year(Today())-1,F5))

Check the initial setting for the date variable: SET DateFormat='DD/MM/YYYY';

tresesco
MVP
MVP


PFA. Hope this helps.

Not applicable
Author

It is the same script that Treseco provided. I value of Year is 2013-2014 instead of 2013. That is the only difference. I am hoping this to work.

@Treseco, Kindly help.

Not applicable
Author

Thanks a ton as usual Treseco.