Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi guys,
I'm facing a problem that I don't know how to solve it.
I have a variable that is calculated in a hard way.
I'm going to explain my problem.
The variable is the result of many others variables.
Something like:
var1 = if(...., SUM(Field1/Field2))
var2 = Sum(field2)/Sum(field3)
var3 = Var1/Var2
var4 = Sum(Field3) * 0.2
var5 = if(....,var5 + 100, if(...., var5 + 200))
var6 = if(...., (var2/var) * 100)
varFinal = var5 / var6
I know it's quite strange but we have to use many variables because all of them is needed to be used in some chart.
Now, I have a straight table that has one dimension.
I'd like to put my varFinal like an expression to have as result that var calculated for any rows of my table.
But, if I build a table like that, the result in every rows is always the same.
Do you think it's possible to reach my goal ?
I hope to be clear.
Any help will be very appreciated
Best regards
Giampiero
Variables are computed over selected values while in a table each value depends on the table's dimensions.
So I think that your goal is unreachable; when you compute your variables I see field2 for instance but are you sure that the used value is exactly what you expect to be?
Hi,
Thank you for reply.
I agree with you, but at the same time I hope that I'm wrong
I'm really feel a beginner on QlikView so I always hope that someone reply to me "Yes, you can do it in this way"
And, Yes I'm sure about the value.
THANK YOU so much
Best regards
Giampiero
Yes, you can do it
But in a slightly different way.
You could use variables not to calculate the result but to store complex expression.
Just remove the = sign from variable expression and then use it like this:
=$(Var1)
If you use it in a chart with dimension, QV substitutes your expression instead of Var1 not just the resulting value.
So I think you could do it, and you should also read about aggr() function.
Hard to say without seeing your complete code, but from what I see it would be challenging. As whiteline said, as a start you'll need to store expression text so the values are not pre-calculated. You'll still need $() references, which will be expanded unless you escape them. Also, there have been subtle timing bugs experienced when deeply nesting variables. I usually recommend nesting no more than one deep. I can also see some self reference stuff in var5 that I don't think would work in a nesting arrangement.
As an alternative, consider putting using the component (smaller) calcs in variables and use those in individual columns in the table. Then do the consolidated calcs like vFinal as references to the other columns. Those other columns can be hidden. See attached for an example.
-Rob
Thank you guys.
All your advices are very precious for me.
Thank you very much and I'm sorry for my late reply.
Giampiero