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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
khaycock
Creator
Creator

Variable in chart

I have a variable that always equals a single number that I am trying to use in a bar chart as an expression. However, when using the variable, it only displays results when there is a selection. 

The variable in question is a sum of many other variables which all have the same issue. 

Below is an example of the flow of how I've done what I've done so far:

1. When a field is blank, if Hobbies is blank, give them 0 points, if there is data, then give them the value of 2.  

vHobbies = if(Hobbies='' or IsNull(Hobbies),0,2)

2. There are then lots of these similar variables like above that are then added together to equal a new variable

vLifestyleRisk = $(vHobbies) + $(vInterests) + $(vPartOfATeam) + $(vDrinker) + $(vReligion) + $(vSexuality) + $(vDietType) + $(vFavouriteSport) + $(vFavouriteTeam) + $(vVocalBeliefs)

3. This variable is then part of another sum which is the variable I am wanting to use in the bar chart:

vOverallRisk = $(vPersonalRiskScore) +$(vFandFRiskScore) + $(vLifestyleRiskScore) + $(vWorkRiskScore)
+ $(vPersonalityRiskScore) + $(vExtrasRiskScore))

For some reason, the variables don't generate the numbers they are meant to generate. When I use the expression separately outside of the variable in a straight table, it works, but when inside the variable, it fails to give any result (see below).

hobbies 1.PNGhobbies 2.PNG

 

I think this is why my variable isn't working in the bar chart but I have no idea why the variable wouldn't generate an amount when it works elsewhere as a normal expression. Why could this be?

Labels (2)
2 Replies
zhadrakas
Specialist II
Specialist II

Hello there,

1)
for the last two variables try to define them like this
vLifestyleRisk = Rangesum($(vHobbies), $(vInterests),$(vPartOfATeam), $(vDrinker) ..)

2) to go save you have number just wrap num( ) around your first variables

3) maybe you want to replace
if(Hobbies='' or IsNull(Hobbies),0,2)
with
if(len(trim(Hobbies))>0, 0, 2)
-> this will also catch field blanks
marcus_sommer
MVP
MVP

I think it's been caused through The-Little-Equals-Sign.

- Marcus