Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Dynamic measure to avoid if-statements

I have a nested if-statement:

if([Category]='Events',[Events],

if([Category]='Delegates',[Delegates],

[Value]))

Is there a qlikview function to dynamically point to a measure field?

I have seen examples where you can dynamically point to a field based on a variable, however based on the row content I want to select the specific measure field.

4 Replies
jerem1234
Specialist II
Specialist II

You can use match() and pick() like:

pick(match(Category, 'Events', 'Delegates', 'Value'), Events, Delegates, Value)

Or if you want if it doesnt match to anything, then use the Value field:

pick(match(Category, 'Events', 'Delegates')+1, Value, Events, Delegates)

Hope this helps!

Not applicable
Author

Thanks, that makes the expression look better and I could store a number in the row to avoid the match function.

However, I was looking for something like =sum(Field(SourceField)) where SourceField is a field in the row and based on the value in that field, QV will use the correct measure.

E.g. if SourceField has the value Events, it will translate Field(SourceField) into Events, returning =sum(Events)

jerem1234
Specialist II
Specialist II

Unfortunately, the only way I have found is using that match(pick()) combo for tables. If you were making selections on the field SourceField and wanted to get the value for the Field selected, you can do something like:

sum($(=SourceField))

However, like I said before, that won't work when referencing values inside the table since $() won't reference whats in the table.

Hope this helps!

Not applicable
Author

Thanks for your reply, will use the pick / match  function.