Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Help with "Conditional Show"

I Have a graph that I only want displayed if a certain year is selected. I have this formula in the Show Conditional formula box on the Layout tab

Year(Date) = Year(Today())

This works if only one year (the current year) is selected, but if I select the current year and last year. Neither of the graphs show up.

What can I do to the formula to display the graph if at least one of the selected values for Year is the current year?

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

SubstringCount(GetFieldSelections(Year),Year(Today()))

Thanks for all of the input, The solution above works perfectly.

View solution in original post

6 Replies
Not applicable
Author

Hi there,

you can try to use the system function like GetFieldSelections.

GetFieldSelections(Date) will give you all selected Date.

you may then try to find the if the year of the maximum date is this year.

The formula sould look at the following:

Year(max(GetFieldSelections(Date) ))=year(today())

Not applicable
Author

I'm not sure if there is an easier way, but this can be accomplished using a macro.

Set an On Select macro for the Year field. Use something like this:

SUB Chooser
set Sello = ActiveDocument.Fields("Year").GetSelectedValues

ActiveDocument.Variables("vGoodYear").SetContent 0, true

for i = 0 to Sello.Count - 1
if Sello.Item(i).text = "2009" then
ActiveDocument.Variables("vGoodYear").SetContent 1, true
end if
next
END SUB

Then you can use the variable in the Show expression. This macro is a simplified version of what you would need. You could set the conditional based on the current year, which looks like what you are trying to do.

Anonymous
Not applicable
Author

I'm going to elaborate a little more on my problem.

I have 3 graphs, one graph I want displayed if one of the selected years is 2009, one for 2008 and the other for 2007.

@npeyroux, the Max() causes your formula to break when multiple years are selected.

Also max is out of the question because 2008 falls in between 2009 and 2007 if all three years were selected.

A macro shouldn't be needed, If I can filter it and have it see the 2008 out of a list within an if then else statement, the same should be possible within an expression. I'd also like to stray away from macros for performance and managability.

GetFieldSelections() seems to be the best bet, but for some reason Max() is not working together with it. Any other suggestions?

Not applicable
Author

Just a quick idea.

I don't know how but may be you can use GetFieldSelections and then a string function to parse the different value.

Not applicable
Author

GetFieldSelections(Year) like Year(Today())

GetFieldSelections(Year) like 2008

etc...

Anonymous
Not applicable
Author

SubstringCount(GetFieldSelections(Year),Year(Today()))

Thanks for all of the input, The solution above works perfectly.