Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I am querying a table with the integer field 'day_of_year', which is the numeric version of the date. The data is agricultural and the users want to see data in-season. Therefore, I am trying to query data between the last occurrence of October 1st and today.
However, because Qlik assumes there are 366 days in each year, the daynumberofyear() function is calculating the wrong day number of year in the script.
How can I create two variables that are always correctly assigned the day number of year for the most recent occurrence of October 1st (e.g., 274 for Oct 1st 2023) and the day of the last data reload (e.g., 307 for today).
Assigning variables:
vTodayDNOY=Date(today())-YearStart(today())+1;
vCYOct1st: makedate(Year(today()), '10','01')-YearStart(today())+1
vPYOct1st: makedate(Year(today())-1, '10','01')-YearStart(makedate(Year(today())-1)+1)
Converting day of year to date in the table:
if(day_of_year <= daynumberofyear(Today(0)),
date(makedate(Year(Today()))+(day_of_year-1)), // if DOY <= today's DOY, assign date from current year
date(makedate(Year(Today())-1)+(day_of_year-1))) // if DOY > today's DOY, assign date from last year
as prediction_date,