Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
Felix_Koch
Contributor II
Contributor II

Variable used in bookmark returns string when using GetFieldSelections()

Hi Qlik Community

I have used a variable for selection of current year in an application: '=Year=$(vCurrentYear)'

vCurrentYear is defined in the data load editor: 'set vCurrentYear = year(today());'

I have a number of KPI's that rely on which year is currentyly selected. I use GetFieldSelections(Year) for this. However, when the default bookmark is applied the KPIs don't work, as the set analysis then returns a string for GetFieldSelections(Year).

Is there a smart way to have the current year automatically selected by the default bookmark but also being able to reference the year that's currently selected in the Year filter?

Br.

Felix

Labels (2)
1 Solution

Accepted Solutions
Or
MVP
MVP

Based on that explanation, shouldn't your KPIs just refer to Year directly? It seems that you require a single year to be selected, so you could just refer to the field rather than look at the selection (or you could use Only(Year) if you want to be explicit)...

View solution in original post

6 Replies
Or
MVP
MVP

I'm not sure I followed that correctly, but if I did, perhaps Coalesce(GetFieldSelections(Year), $(vCurrentYear))? This will use a selection if one exists, and otherwise use whatever is in the variable.

Felix_Koch
Contributor II
Contributor II
Author

Hi Or

I didn't know that function, really cool!

However, I think the issue remains the same. Coalesce(GetFieldSelections(Year), $(vCurrentYear)) returns '=Year=$(vCurrentYear)' when the abovementioned bookmark is applied. Apparently a strings is still recognized as a "valid non-NULL representation" for the 'Coalesce' function.

Or
MVP
MVP

I am a tad confused here - a default bookmark is applied before any user selections can be made, so how would the field selections even come into play in this regard? Shouldn't you just use =Year=Year(Today()) for the bookmark?

Felix_Koch
Contributor II
Contributor II
Author

Maybe my explanation is just a bit unclear, I'll give it another go based on your point regarding the bookmark.

There is a default bookmark that selects the current year: =Year=Year(Today()).

Then there's a number of KPIs. Most of the KPI's show changes in amounts relative to Dec-PreviousYear. In order for the KPIs to understand which year is the previous year, they need to understand which year is currently selected (2022 should be compared to dec-2021 and 2021 should be compared to dec-2020). That part works when a year is manually selected, but when the bookmark is applied, the value returned for Year is =Year=Year(Today()) instead of 2022.

Hopefully the problem makes a bit more sense now.  Otherwise please let me know 🙂

Or
MVP
MVP

Based on that explanation, shouldn't your KPIs just refer to Year directly? It seems that you require a single year to be selected, so you could just refer to the field rather than look at the selection (or you could use Only(Year) if you want to be explicit)...

Felix_Koch
Contributor II
Contributor II
Author

Yay, looks like only(Year) did the trick for me!

Thank you!