Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Half Year To Date HYTD ?

I need to create a Half Year To Date type of function. I know that there is no inhalfyeartodate function so I am trying to manually create it. I went down this road:

IF(MONTH($(varToday)) < 7, inyeartodate(TempDate, $(varToday), 0) * -1,
IF(MONTH($(varToday)) < 10, inquartertodate(TempDate, $(varToday), 0) * -1,
IF(MONTH($(varToday)) < 13,inquartertodate(TempDate, $(varToday), 0) * -1))) AS CurHYTDFlag


The problem here is that when the current date is in the last quarter, it will only flag the dates in last quarter rather than last quarter AND the quarter before.

Any suggestions are appreciated!

Aaron

3 Replies
Not applicable
Author

Instead of having a pain about how to calculate the flag, it's much easier to calculate real YTD or HYTD of MTD in charts.

Here is unique expression for this:

This is YTD of current Year for date range selection


sum({1 <Date={"$(='>=' & YearStart(max({$} Date)) & '<=' & max({$} Date) )"}>} total Amount)


All what you need is just to replace bold part by start date of your period. In your case, it should be like this:


sum({1 <Date={"$(='>=' & AddMonths(YearStart(max({$} Date)), 6) & '<=' & max({$} Date) )"}>} total Amount)


See the example in attachment.

Anonymous
Not applicable
Author

I am trying to keep as many calculations as possible inside the script for UI efficiency sake, but this suggestion is good.

Thanks for your input.

Aaron

Not applicable
Author

Ok. Here is your half year to date flag expression:


=if(year(Date) = year(today()), if(InYearToDate(Date,YearStart(today()), 1, 7), 'Second half of Year', 'First half of Year'))