Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Qlikview simple variable gives unexpected results in bar chart

I get data from a small sample SQL server table -

IdEmployeeSalesAmount
1a2000
2a500
3b300
4b3000
5c100
6c1500
7d1000

let var1 = 1000;

SQL SELECT * FROM Sales Where SalesAmount >= $(var1);

The table box for this looks like -

Id Employee SalesAmount
1a2000
4b3000
6c1500
7d1000

In chart, Measure is SumOfSales by Dimension Employee.

If I set the expression for dimension employee as =Sum(SalesAmount), I see the table box values on the chart.

But when I do the same thing using a variable, ie var2 =Sum(SalesAmount) and bar chart employee =($var2),

I get sum of all employees sale instead of sum of each employees sale. Why does this happen and how do I correct it ?

1 Solution

Accepted Solutions
MK_QSL
MVP
MVP

Please check enclosed file...

View solution in original post

6 Replies
Not applicable
Author

This is working as designed.

Variables are calculated "outside" of the chart, so the context of the Employee dimension is not brought in to the equation. The variable is calculated entirely independent of the chart and will remain even if the chart object is deleted. Selections will change your variable but not dimensions as you are seeking above.

You wouldn't generally want a variable to behave the way you described. Is there something specific you were attempting that your first expression wouldn't work for?


EDIT:

Apologies, but I hastily overlooked something before that reading your other post made me think about. If your goal is to store the string for expression as this variable, make sure you remove the equal sign in your variable definition. The equal sign is what triggers qlikview to evaluate the expression rather than just store the string.

MK_QSL
MVP
MVP

Please check enclosed file...

its_anandrjs

Take a dimension Id, Employee and take a variable

var2 =Sum(SalesAmount)


and in dimension use a variable like $(var2)


Hope this helps

Thanks & Regards

mangalsk
Creator III
Creator III

Hello,

While creating variable don't give equal sign

just write sum(SalesAmount) instead of '=sum(SalesAmount)'

and while using in expression write

=$(var2)

instead of =($var2)

Regards

Not applicable
Author

Thank you very much for the example. Much appreciated.

MK_QSL
MVP
MVP

Glad that you found it useful.

Hope your problem solved.

Kindly close the thread by selecting correct answer...