5 Replies Latest reply: Jan 7, 2016 9:02 PM by surfman joe

# a YTD choice

Now I have a bar chart in QLIK SENSE shows this year and last year sales data.As default, the graph will show this year YTD data and whole last year data.

I want to offer a choice to user to pick YTD data, once YTD was picked, the graph will show this year YTD data (same as default) and same period data in last year.

Can any help on how to achieve this goal? especially how to provide the YTD choice and how to interact with it. thanks.

• ###### Re: a YTD choice

Usually we create conditional flags, such as a CYTD_Flag that are assigned 0 or 1, depending on the condition. With the flag pre-calculated in the data load script, it's easy to select the YTD and the Last YTD data using Set Analysis:

sum({<CYTD_Flag = {1}>}  Sales) -

sum({<LYTD_Flag = {1}>}  Sales)

cheers,

Oleg Troyansky

Take your Qlik Skills to the next level at the Masters Summit for Qlik - now with new and redesigned materials!

• ###### Re: a YTD choice

Thanks for both of answers. I still have question on how to implement on UI. is that possible show me a simple sample?

I am new and much appreciated your elaboration.

• ###### Re: a YTD choice

Hi surfman,

Check this out:

Check the attached qvf for more details .

#

Thanks and Regards,

Sangram Reddy.

• ###### Re: a YTD choice

fantastic! Much appreciated.

• ###### Re: a YTD choice

Hi Sufman,

In Script

You can set the Current year to date flag using :

inyeartodate(Date,today,0) * (-1) as CYTD  - this will flag (1) if the date falls in the current year to date period.

You can set the Current year to date flag using :

inyeartodate(Date,today,-1) * (-1) as LYTD  - this will flag (1) if the date falls in the last year to date period.

Use these flags in the set analysis expressions.

sum({<CYTD_Flag = {1}>}  Sales) -

sum({<LYTD_Flag = {1}>}  Sales)

Thanks,

Sangram Reddy.