Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
waleeed_mahmood
Creator
Creator

Defining Set variables with functions in them

Hi I have variables defined in my load editors and they are something like this:

SET v1 = Sum({$<[VIType]={'Account'}, [FQuarter]={"<=$(=right(GetFieldSelections(FQuarter),1))"}, [fYear]-=>} [Customer Targets]) ;

If i use them in a table like

=Sum({$<[VIType]={'Account'}, [FQuarter]={"<=$(=right(GetFieldSelections(FQuarter),1))"}, [fYear]-=>} [Customer Targets]) 

it works fine. However, when i use this variable in a table like $(v1), it doesnt work. The statement in "" doesnt resolve.

It shows [FQuarter]={"<="}.

Any ideas how to fix this?

 

Thanks 

Labels (1)
1 Solution

Accepted Solutions
Rohan
Specialist
Specialist

Hi @waleeed_mahmood ,

I think the issue is with using Right(). You are passing something like :

FQuarter={"<=2"}, when selection is FQuarter is Q-2. but your field FQuarter is a string, such range selections wont work on string field. Instead you need to create another Field FQuarterNum in your calendar which will have numerical values 1,2,3,4 for Quarter. & use that in your set variable.

FQuarterNum={"<=$(=right(GetFieldSelections(FQuarter),1))"}

Try something like this, & Let me know if it worked.

*Edit*

Hi, I later realized that getfieldselections won't pass a single selections until Select only one value is enabled for that specific field. Check on that part as well.

 

Regards,

Rohan.

 

View solution in original post

5 Replies
Rohan
Specialist
Specialist

Hi @waleeed_mahmood ,

Have you tried using '=' before the Variable in the measure expression ? Also this expression wont evaluate until you make selections in the Quarter field on the dashbaord.

 

Regards,

Rohan.

vincent_ardiet_
Specialist
Specialist

Try with:

LET v1 = 'Sum({'&chr(36)&'<[VIType]={''Account''}, [FQuarter]={"<='&chr(36)&'(=right(GetFieldSelections(FQuarter),1))"}, [fYear]-=>} [Customer Targets])' ;

waleeed_mahmood
Creator
Creator
Author

Hi, Its not a variable but a field in my master calendar. and yes the quarter selection is fixed.

Rohan
Specialist
Specialist

Hi @waleeed_mahmood ,

I think the issue is with using Right(). You are passing something like :

FQuarter={"<=2"}, when selection is FQuarter is Q-2. but your field FQuarter is a string, such range selections wont work on string field. Instead you need to create another Field FQuarterNum in your calendar which will have numerical values 1,2,3,4 for Quarter. & use that in your set variable.

FQuarterNum={"<=$(=right(GetFieldSelections(FQuarter),1))"}

Try something like this, & Let me know if it worked.

*Edit*

Hi, I later realized that getfieldselections won't pass a single selections until Select only one value is enabled for that specific field. Check on that part as well.

 

Regards,

Rohan.

 

waleeed_mahmood
Creator
Creator
Author

Hi Rohan,

This made alot of sense why it wasnt working. thanks.