# QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

Highlighted
Contributor 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!

Aaron

Tags (4)
3 Replies Not applicable

## Half Year To Date HYTD ?

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.

Contributor III

## Half Year To Date HYTD ?

I am trying to keep as many calculations as possible inside the script for UI efficiency sake, but this suggestion is good. `=if(year(Date) = year(today()), if(InYearToDate(Date,YearStart(today()), 1, 7), 'Second half of Year', 'First half of Year'))`