Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Save $650 on Qlik Connect, Dec 1 - 7, our lowest price of the year. Register with code CYBERWEEK: Register
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

YTD button

Hey Guys,

I'm trying to make a button that when clicked the MonthYear will select Year to date.

So, for example, right now I have data from Jul-2009 to Nov-2010.

I want Jan-2010 to Nov-2010 selected.

Right now I have an action Select in Field. The Field is set to MonthYear and the search string is = '>=Jan-2010' AND '<=Nov-2010'

I can get it to work with >=Jan-2010 and I can get it to work with <=Nov-2010 but not together.

Any ideas?

1 Solution

Accepted Solutions
Not applicable
Author

I don't think you need the And in there. Range selections are defined in Set Analysis by combining both conditionals. Try:

= '>=Jan-2010<=Nov-2010'


I don't think I've ever tried that in an Action, but I would assume that is how it is done.

View solution in original post

5 Replies
Not applicable
Author

I don't think you need the And in there. Range selections are defined in Set Analysis by combining both conditionals. Try:

= '>=Jan-2010<=Nov-2010'


I don't think I've ever tried that in an Action, but I would assume that is how it is done.

Not applicable
Author

That did the trick. Thanks!

johnw
Champion III
Champion III

As a possible alternative, you could handle it in the data model by having a 'YTD' value for a "Date Range" field. It could even be the only value if you wanted, though it might be more useful to have some other alternatives in there. Then have a table that associates date range values with the actual dates, perhaps created with an intervalmatch. Selecting YTD from a list box would then "select" the appropriate months. If it's the only value, you could handle it by giving it a windows checkbox format, perhaps.

Now that I'm thinking about it, I remember that Rob Wunderlich made an example like this in his QlikView Cookbook:

http://robwunderlich.com/Download.html

Not saying it's better than having a button. The button might be more clear, particularly if there's only one such date range you want to select. But if you wanted several, I'd think the buttons would start taking up too much space, and start seeming like a clunky and un-QlikView-like way of making selections.

I've certainly done selection buttons myself, though. Nothing really wrong with that. Just wanted to toss an alternative out there.

Oh! Let me toss something else out there if you use buttons like this. If you want to go a bit overboard, here's what I did with one such button so that it would highlight in light green when pressed, and then change back to gray if any selections were modified. First, the button executes a selection macro, and the last step of the selection macro records the current selections in a variable:

sub CustomerOrders
call CommonSelections
set field = activedocument.fields("Order Item Type")
field.select "PRIME"
set field = activedocument.variables("CustomerOrders")
field.setcontent activedocument.evaluate("getcurrentselections()"),false
end sub

It's the last two lines of the macro that are of interest here. Then I create a calculated color expression for the button:

if(getcurrentselections()=CustomerOrders,lightgreen(),lightgray())

So when I press the button, it makes the selections, stores the selections in a variable, and then the color expression keeps the button green as long as these exact selections stay active. In your case, you might want to only grab the current selections for the month field rather than all selections. I needed all selections because the button represents a standard way of looking at things that everyone should share, and if you aren't looking at it that standard way, I wanted that to be visually evident with a glance at the screen.

johnw
Champion III
Champion III


NMiller wrote:I don't think you need the And in there. Range selections are defined in Set Analysis by combining both conditionals. Try:<blockquote>= '>=Jan-2010<=Nov-2010'<pre>

I don't think I've ever tried that in an Action, but I would assume that is how it is done.



I believe they're both interpreted exactly the same because they're both advanced search expressions. You can enter an advanced search expression in set analysis, and you can enter an advanced search expression in a selection action. The syntax is a little different, with the set analysis putting it in double quotes and the search expression requiring an equals sign and single quotes, but the rest of the expression should be exactly the same. Anything you can search for in double quotes in set analysis should in theory be allowed in a select action search expression and vice versa.

Not applicable
Author

Thanks for the notes John.

I actually did do the green gray as well.

In the font color expression I used:

if(
min(MonthYear) = date(yearstart(vLastDay3), 'MMM-YYYY')
AND
max(MonthYear) = date(monthstart(vLastDay3), 'MMM-YYYY')
, rgb(68, 248, 36), black(150))