Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
surajap123
Creator III
Creator III

parameterized variable for color

Hi,

I am trying to use parameterized variable with rgb color as a parameter. It seems the comma in the RGB() function is causing the issue and the expression is not working.

I have using this expression in the attached app to give background color to the dimension in chart.

=$(vVar(rgb(241,82,73))) //Not working

vVar   =if(sum(Sales) < 110,rgb(241,82,73))  //Actual expression


Please help!

Labels (1)
1 Solution

Accepted Solutions
rwunderlich
MVP
MVP

You can't pass a parameter that includes commas in the value.  The commas are always interpreted as parameter separators.  What you can do is add a DSE to calculate the numeric value of the RGB code and pass that. Like this:

=$(vVar($(=num(rgb(241,82,73)))))

Because RGB returns a Dual, you must extract the num otherwise QV will attempt to pass the string representation.  This is true even if you use script created variables.

LET vColor = RBG(1,2,3);

LET vColorNum = num(RGB(1,2,3));

$(vVar($(vColor)))  // won't work

$(vVar($(vColorNum)))  // will work

Update:  Actually, a color variable with a LET will work if you pass it as a direct reference, no DSE.

$(vVar(vColor))  // will work


That's because variables passed as parameters like this will be passed by reference, not value.

-Rob

http://masterssummit.com

http://qlikviewcookbook.com

View solution in original post

6 Replies
Anil_Babu_Samineni
MVP
MVP

May be create variable like

If($1=1, If(sum(Sales) < 110,rgb(241,82,73)))

BG Color like $(vVar(1))

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
surajap123
Creator III
Creator III
Author

Hi Anil...Thanks for your reply.

I am creating this parameterised variable to improve the performance of my real expression which is different.

I am looking to have the RGB function directly in the variable as a parameter. Do you think its not possible.

Thanks!

Anil_Babu_Samineni
MVP
MVP

Yes, I am thinking about how we can overcome this issue. May be stalwar1‌ help you

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
rwunderlich
MVP
MVP

You can't pass a parameter that includes commas in the value.  The commas are always interpreted as parameter separators.  What you can do is add a DSE to calculate the numeric value of the RGB code and pass that. Like this:

=$(vVar($(=num(rgb(241,82,73)))))

Because RGB returns a Dual, you must extract the num otherwise QV will attempt to pass the string representation.  This is true even if you use script created variables.

LET vColor = RBG(1,2,3);

LET vColorNum = num(RGB(1,2,3));

$(vVar($(vColor)))  // won't work

$(vVar($(vColorNum)))  // will work

Update:  Actually, a color variable with a LET will work if you pass it as a direct reference, no DSE.

$(vVar(vColor))  // will work


That's because variables passed as parameters like this will be passed by reference, not value.

-Rob

http://masterssummit.com

http://qlikviewcookbook.com

sunny_talwar
MVP
MVP

Check if the attached works for you

surajap123
Creator III
Creator III
Author

Thanks you so much for the solution and the explanation..rockstar