Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

alvinford
New Contributor III

Year Start and End

Hi All,

I have the following requirement. Need your help to get it !

I have to take my year start as last Sunday of April i.e. 28/04/2013.The Week is from Sunday to Saturday. How can I develop this logic in Qlikview. So from 28/04/2013 to 26/04/2014 need to take as "This Year" and 29/04/2012 to 27/04/2013 as "Last Year". How can I derive this.

Regards,

Alvin

1 Solution

Accepted Solutions
MVP
MVP

Re: Re: Year Start and End

Sorry, I don't understand your last request and how it is related to the year start on last sunday in April.

Attached my sample solution, you should see the year start and year end matches your requested dates as of your initial post.

4 Replies
MVP
MVP

Re: Year Start and End

Try something like

Calendar:

LOAD if(Date < weekstart(makedate(year(today())+1,4,30),0,-1) and Date >= weekstart(makedate(year(today()),4,30),0,-1), 'This Year',

            if(Date < weekstart(makedate(year(today()),4,30),0,-1) and Date >= weekstart(makedate(year(today())-1,4,30),0,-1), 'Last Year')) as YearFlag,

    Date;

LOAD

Date(makedate(2012)+recno()-1) as Date

AUTOGENERATE 1000;

weekstart( makedate(2013,4,30), 0, -1) should return the last sunday in April 2013, change the input date for other years.

alvinford
New Contributor III

Re: Year Start and End

Hi Swuehl,

Thank you very much for the reply.

The Last Year is starting from 26/03/2012. But as 01/04/2012 is sunday it has to start from 01/04/2012.

If the NextMonth start is Sunday we have to consider that week as the First Week.

Request your help to change the logic accordingly.

Regards,

Alvin.

MVP
MVP

Re: Re: Year Start and End

Sorry, I don't understand your last request and how it is related to the year start on last sunday in April.

Attached my sample solution, you should see the year start and year end matches your requested dates as of your initial post.

christian77
Valued Contributor

Re: Year Start and End

Hi.

I recomend you to do that in the script.

Also I recomend you not to use an if clause.

Instead do the next.

LOAD

Year(Date)                                        as Year,

Year(Date-Nº of days)                  as FixedYear

Being Nº of days the number of days between that last sunday of April that you want, and your Date data.

You'll have to work it out a little bit more for your script.

good luck.

Community Browser