Qlik Community

Ask a Question

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Join this live chat April 6, 10AM EST - QlikView to Qlik Sense REGISTER
Showing results for 
Search instead for 
Did you mean: 
Creator III
Creator III

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!


3 Replies
Not applicable

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.

Creator III
Creator III

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.


Not applicable

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'))