# New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Announcements
Make your voice heard! Participate in the 2020 Wisdom of Crowds® Survey. BEGIN SURVEY
Highlighted
New Contributor

## Date Functions

Hi,

I have a date variable (Date_In) formatted YYYY-MM-DD.

I need some logic please to calculate YTD as currently I hard code it in like below:

DATE_IN = {"2018*"}

It would be useful to have another calculation for previous year too please as I do the same as above:

DATE_IN = {"2017*"}

Thanks

6 Replies
Highlighted
Partner

## Re: Date Functions

Hi ,

you could try:

DATE_IN{">=2018-01-01 <=2018-12-31"} for example.

Same for 2017.

Highlighted
Partner

## Re: Date Functions

And you can make the date fields dynamic if you want. Like:

DATE_IN(">=\$(=MIN(DATE_IN)) <=\$(=MAX(DATE_IN))"}

Highlighted
Partner

## Re: Date Functions

Hi,

Try YEARTODATE function in

Highlighted
New Contributor

## Re: Date Functions

Thanks for your suggestions but I can't quite get it to work, this is the full code below, any ideas please?

RangeSum(Above(Sum({<[Country] = {'UK'}>}if(Left(DATE_IN,4)='2017'
and Lookup='Renewal_Value',Val)),0, RowNo()))
/
RangeSum(Above(Sum({<[Country] = {'UK'}>}if(Left(DATE_IN,4)='2017'
and Lookup='due for renewal' ,Val)),0, RowNo()))
Highlighted
New Contributor

## Re: Date Functions

Anyone able to assist with the above logic please?
Highlighted
Partner

## Re: Date Functions

You should make a flag in your calendar script:

```InYearToDate(<DateField>, Today(), 0) * -1   AS CYTDFlag
InYearToDate(<DateField>, Today(), -1) * -1  AS LYTDFlag```

Then use the flag in your set analysis:

`SUM({\$< CYTDFlag = {1}>}  <Field> )`