Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello everybody,
I have a problem which bothers me a lot. And I hope anyone of you can help me...
In my data model I have 3 different fields, called Col1, Col2 and Col3. Furthermore I have a field relevantCol which consists of the names of the three fields before. Now I would like to create an expression which returns the values of the columns mentioned in relevantCol.
I tried to use the expression
$(=relevantCol)
But this works only if one unique relevantCol has been chosen.
I think it will be clear if you have a look at the attached qvw. Just choose one item under relevantCol.
Is it possible to modify the expression in a way that it shows always the correct value?
Thanks a lot!
Great solution!
Thanks a lot.
Unfortunately, I can't use this expression cause of performance reasons... (I need this formula about 10 times for ca. 1 Mio rows.)
😞
But that was exactly what I needed.
Best regards,
Dae-Wie
Dae-Wie,
I'm sorry the performannce didn't work out.
I'm curious about the scenario you are trying to use this in. Can you describe your real world applicaion of this?
Thanks,
Rob
It seems like we should be able to do evaluate(relevantCol). But QlikView explicitly disallows this function in charts. Why? No idea!
I'm guessing that the pick(match()) approach is slow because it's doing so very much string manipulation when setting up the variable. If it's doing it for every row of the chart, which seems likely, then that could certainly bog you down.
But maybe we're reading too much into where you said "...there will be more columns than 1 to 3. But it's not clear how much more, cause they can will be added dynamically."
What do you MEAN by added dynamically? You can't actually create fields anywhere but in the script. The only fields that can be referenced are fields loaded in the script. So I would think that building the variable in the script would be perfectly safe. But I'm not sure I'd even go that far. I think I'd just write the expression in the chart, and remember that if I add a field to the script that I want to use in the chart, I have to add it to the chart.
So I'm recommending that, for performance reasons, you simply use Rob's original expression (formatted below for easier verification that your literals match your field names):
pick(match(relevantCol
,'Col1','Col2','Col3')
, Col1 , Col2 , Col3 )