Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content
Announcements
WEBINAR June 25, 2025: Build on Apache Iceberg with Qlik Open Lakehouse - REGISTER TODAY
cancel
Showing results for 
Search instead for 
Did you mean: 
iliyansomlev
Partner - Creator II
Partner - Creator II

expand a variable in an alternate state

Hi, everyone,

 

In QV May 2024 alternate state description (https://help.qlik.com/en-US/qlikview/May2024/Subsystems/Client/Content/QV_QlikView/Alternate%20State...), at the end is stated:

If you have a state named MyState, and a variable named vMyVar:

  • $(vMyVar) expands the variable in the default state.
  • $({MyState} vMyVar) expands the variable in the MyState state.

I have a Calendar where each date (field Date) has its Year (column Year); I then have a variable vMaxDate = max(Date) and 2 selectors (List Boxes of the field Year) - one in default state and another in a state PY

when I write in a text box ='$(vMaxDate)' it returns 31.12.2025 ; if 2025 is selected from the first selector.

when I write in a text box ='$({PY}vMaxDate)' and select 2024 from the second selector, nothing is displayed (blank), but if I write =max({PY}Date) in the text box, then 31.12.2024 is shown. 

Do you know why variable expansion in alternate state is not working as explained?

Labels (1)
1 Solution

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I think the doc is wrong (typo). The state name should be outside the $. Like this:

{MyState} $(vMyVar) 

Or in your case, 

{PY} $(vMaxDate)

-Rob
http://www.easyqlik.com
http://masterssummit.com
http://qlikviewcookbook.com

View solution in original post

3 Replies
marcus_sommer

I think the linked documentation with it's examples isn't clear enough to the general logic and behaviour of a variable. Better is the description on this place:

Dollar-sign expansion using a variable | QlikView Help

which makes rather clear that a variable could have always only a single value at the same time. A field could belong to n states which means that parallel to the system-table a state-table is placed but such logic isn't simply applicable to variables because there is only one value whereby the fields have n ones.

This means you need to apply the state within the expression or by using outer sets before the expression and this expression might be within a variable.

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I think the doc is wrong (typo). The state name should be outside the $. Like this:

{MyState} $(vMyVar) 

Or in your case, 

{PY} $(vMaxDate)

-Rob
http://www.easyqlik.com
http://masterssummit.com
http://qlikviewcookbook.com

iliyansomlev
Partner - Creator II
Partner - Creator II
Author

Thank you for answering, unfortunately {PY} $(vMaxDate) is not working either. 

But it is not working because my variable is Global (defined as =Max(Date))

when I make it local (Max(Date), then it is working (First is alternate state selector on 24/3, second cell is default state on 25/3

 

={PY}$(vMaxDate)      $(vMaxDate)

 31.03.2024              31.03.2025