Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I get data from a small sample SQL server table -
Id | Employee | SalesAmount |
1 | a | 2000 |
2 | a | 500 |
3 | b | 300 |
4 | b | 3000 |
5 | c | 100 |
6 | c | 1500 |
7 | d | 1000 |
let var1 = 1000;
SQL SELECT * FROM Sales Where SalesAmount >= $(var1);
The table box for this looks like -
Id | Employee | SalesAmount |
---|---|---|
1 | a | 2000 |
4 | b | 3000 |
6 | c | 1500 |
7 | d | 1000 |
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 ?
Please check enclosed file...
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.
Please check enclosed file...
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
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
Thank you very much for the example. Much appreciated.
Glad that you found it useful.
Hope your problem solved.
Kindly close the thread by selecting correct answer...