Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
TomBond77
Specialist
Specialist

Year to date, current and last year

Hi experts

I have a loading script to get current years YTD:  if(InYearToDate(%Key_Date,Today(),0) * (-1)>0,1) as YTDFlag

But we need to be more flexible / dynamic, depending on the selected year the YTD must change. This logic gives an error while loading:  if(InYearToDate(%Key_Date, max(year(%Key_Date)),0) * (-1)>0,1) as YTDFlag

 

Any ideas?

Thank you, Tom

Labels (5)
1 Reply
Or
MVP
MVP

You can't have a script expression reference a user selection, so even if the syntax was correct, this wouldn't work. You'll have to write this expression on the front end, not in the script, if you want it to reference a selection.

Typically this would be handled by using InYearToDate(Field) to create a flag of whether a date is within the YTD range (for any year) and then applying that flag in set analysis on the front end. You would handle the year aspect separately within the same set analysis.