Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
chvl
Contributor
Contributor

Use text as expression

I have a table like this in my editor:

Load * Inline [
category_tag_id, color, color_code
1, green, RGB(142,165,14)
2, yellow, RGB(255,242,0)
3, orange, RGB(255,153,0)
4, red_light, RGB(255,102,0)
5, red_dark, RGB(210,0,25)
];

Now, I would like to use the RGB-formulas as color-codes in my table.

Every product is linked to the table via the category_tag_id.

Is there an easy way to tell Qlik to use the code in the color_code-column as an expression?

That would save me from writing multiple If-statements.

 

Best regards,

Christian

1 Solution

Accepted Solutions
marcus_sommer

By a single resolution the $-sign expansion should work but if there are multiple colours possible it returned only one colour back because the $-sign expansion creates an adhoc-variable which is evaluated before the chart and then applied there to all their calls.

But you don't  need the rgb() evaluation because you could also specify the pure numeric color-index instead. You could get these values just by using a formatting like: num(rgb(r,g,b))

More background to the logic could you get here:

Colors in Qlik - Qlik Community - 1484386

- Marcus

View solution in original post

7 Replies
Or
MVP
MVP

chvl
Contributor
Contributor
Author

You mean like $(=color_code) or $(color_code) ? Both don't work when I put them in expressions for color. I tried in a simple table and used the formula for the background color.

marcus_sommer

By a single resolution the $-sign expansion should work but if there are multiple colours possible it returned only one colour back because the $-sign expansion creates an adhoc-variable which is evaluated before the chart and then applied there to all their calls.

But you don't  need the rgb() evaluation because you could also specify the pure numeric color-index instead. You could get these values just by using a formatting like: num(rgb(r,g,b))

More background to the logic could you get here:

Colors in Qlik - Qlik Community - 1484386

- Marcus

chvl
Contributor
Contributor
Author

Hi Marcus,

you mean like using the table with three columns "R", "G", "B" and then use the rgb formula with these columns in Qlik?

tresesco
MVP
MVP

While getting row-wise expressions from script, you can evaluate them with an expression like:

Pick( RowNo(total),$(=Concat(color_code, ',',category_tag_id)))

tresesco_0-1637914381374.png

 

marcus_sommer

Although using separate fields for the single colours is a method to specify the wanted values it wasn't meant in regard to avoid an evaluation of functions else applying the num() wrapping to get the underlying index-value which is then directly used, like:

num(rgb(142,165,14))

returned the value of: 4287538446

means you would try it with:

Load * Inline [
category_tag_id, color, color_code
1, green, 4287538446
...];

- Marcus

chvl
Contributor
Contributor
Author

Thanks Marcus for the help.

Based on your hints, I figured out that there was another very simple solution if you have prepared the data like I did.

I just needed to put in =color_code in the expression for color and it worked.

The only thing I needed to adjust to put quotes around the values in the data load editor (like this: 'RGB(145,165,14)' ) which is quite nice.