Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
shaosiong
Partner - Contributor III
Partner - Contributor III

YTD vs LYTD

HI Qlik Experts

I have a dataset containing sales data which ranges from 1 Apr 2007 to 31 Mar 2009.

I am currently comparing the YTD and LYTD sales and have the below script which looks fine and returns me the accurate YTD and LYTD for any particular selection I wanted.

vMaxYear=max(Year)

vPriorYear=vMaxYear -1

vMaxDate=max(Date)

vPriorYearDate=date(addyears(max(Date), -1), 'DD/MM/YYYY')

YTD

='YTD $(vMaxDate)'

LYTD

='YTD $(vPriorYearDate)'

=SUM({<

Year={"$(vMaxYear)"},

Month=,

Day=,

Date={"<=$(vMaxDate)"},

MonthYear=

>}Sales)

=SUM({<

Year={'$(vPriorYear)'},

Month=,

Day=,

Date={'<=$(vPriorYearDate)'},

MonthYear=

>}Sales)

 

However, my issue with this script is when I am not selecting any dates, by default it gives me the YTD for 2009 (till 31 Mar which is the max date) and the Sum of Sales of entire year for 2008 for my LYTD. I wish to let the default for LYTD be until 31 Mar 2008 as well.

Any advise on this??? Thank youuu!

1 Reply
shaosiong
Partner - Contributor III
Partner - Contributor III
Author

As per attached.