Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

nicalbert
New Contributor III

Using a button to create a selection

Hi everyone,

I there a way to select dates using a button? I need to add a button that dynamically selects the last 7 days based on the current date.

I tried the following, without any luck:

  • Created a button with "Select in field" as Action
  • Identified the date field (in this case ItemCreatedDate)
  • Used the following search string:  ='>=' & Date(Today()-7) & '<=' & Date(Today())
    • Just tried it... I'm not sure about that one!

Does the format of ItemCreatedDate can influence the result? In this case, the format is "YYYY-MM-DD hh:mm:ss".

Can somebody help me on that one?

Nic

1 Solution

Accepted Solutions

Re: Using a button to create a selection

When changing the date field name, the search string has to be changed accordingly:

So instead of

QlikCommunity_Thread_287710_Pic3.JPG

you should use a search string like

QlikCommunity_Thread_287710_Pic4.JPG

hope this helps

regards

Marco

11 Replies
YoussefBelloum
Esteemed Contributor

Re: Using a button to create a selection

Hi Nicolas,

Yes it may not work because of the format..

today() is a date and Date(today()) is a date also

your field ItemCreatedDate is a TIMESTAMP, you should interpret this field and format it as a date before, you can create a derived field in the script like this:

Date(Date#(ItemCreatedDate , 'the format you have on the DateFormat variable ')) as new_field_name


! on the button, when you identiy the Date field, make you to not put = sign !

Re: Using a button to create a selection

Perhaps this? Or please post application to test, If dates are real date format then this should work

='>=' & Date(Max(ItemCreatedDate-7), 'YYYY-MM-DD') & '<=' & Date(Today(), 'YYYY-MM-DD')

shiveshsingh
Honored Contributor

Re: Using a button to create a selection

You need to use interpreter to change the format of your Item CreatedDate

May be this..

Date((ItemCreatedDate-7),'YYYY-MM-DD')

jonashertz
New Contributor III

Re: Using a button to create a selection

Yes I beleive the format influence the result.. As a test you can try the very same search string in the search box for a List Box object containing the field you wish to search.

Actually you can (and perhaps should?) remove the time part from your ItemCreatedDate if only the date part is relevant.

Else try the following script in an empty app to examine some options for creating a timestamp for your button:

Load

date(Today()-7) as Today,

timestamp(Now()-7) as Now,

timestamp(Date(Today()-7) & ' 00:00:00') as Timestamp,

Date(Today()-7) & ' 00:00:00' as Text

AutoGenerate 1

Re: Using a button to create a selection

Hi,

one solution could be to use the expression search syntax, thus avoiding date format issues:

QlikCommunity_Thread_287710_Pic1.JPG

QlikCommunity_Thread_287710_Pic2.JPG

='=Date>Today()-7 and Date<=Today()'

see also:

The Search String

The Expression Search

hope this helps

regards

Marco

nicalbert
New Contributor III

Re: Using a button to create a selection

HI Marco,


the example you have provided is exactly what I need to to! But for some reason, it does not work with my actual data.

Re: Using a button to create a selection

Can you please post a sample of your data to test with?

thanks

regards

Marco

nicalbert
New Contributor III

Re: Using a button to create a selection

There you go!

Thanks again for your help.

Nicolas

Re: Using a button to create a selection

When changing the date field name, the search string has to be changed accordingly:

So instead of

QlikCommunity_Thread_287710_Pic3.JPG

you should use a search string like

QlikCommunity_Thread_287710_Pic4.JPG

hope this helps

regards

Marco

Community Browser