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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
curiousfellow
Specialist
Specialist

calculate correlation using variable

I want to calculate the correlation between the answers of two questions.

So I made a variable to calculate the sum of one question. (OverallQuestion) :=Sum({1<question={'finalquestion'}>}answer)

The answer to the questions is allways numeric (or null)

However when I make an expression like  =correl($(Overallquestio),Question) i don't get results.

Some questions were not answered, so there are null-values

Is it possible to use variables in the function Correl ?

4 Replies
marcus_sommer

Generally you could use variables for nearly each part from dimensions or expression - it's only a question from the syntax.

If you used the syntax "= AnyExpression" for a variable the variable will be global calculated without any relation to objects or dimensions. If you want use the variable as replace for a expression then without the equal-sign. Further the call from variables needed often a $-expansion like $(=variable), see also:

The Magic of Variables

The Magic of Dollar Expansions

Therefore try something like this:

variable:

Sum({1<question={'finalquestion'}>}answer)

expression:

correl($(=Overallquestion),Question)

And by problems with NULL could be a rangecorrel() helpful.

- Marcus

curiousfellow
Specialist
Specialist
Author

For $(=Overallquestion) I get a result. But when I enter Correl($(=Overallquestion),$(=Overallquestion)) I don't get a result (only a '-'). Should be 1



Strange.. or am I missing something ?

marcus_sommer

Maybe there are any invalid values or NULL on the level from the aggregation. Try to handle it with rangecorrel() or $(=alt(Overallquestion, DefaultValue)).


- Marcus

gshockxcc
Creator
Creator

Your variable "OverallQuestion" contains a basic aggregation function.  You can't use this in Correl unless you use TOTAL.

See if this fixes your error.