Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Evan0211
Creator
Creator

Setting result of IF statement to dimension

New to Qlik and have a question on storing the outputs of an if statement to a custom dimension to be used in charts.

Basically, what I want to do is something like this:

if([date] > Today, 'Future', 'Past')

Then be able to say if [CustomDimension] = 'Future', do something (count the number of records returned, custom coloring, etc)

How do I save the if statements value to a custom dimension to use elsewhere without having to reuse the if statement?

Labels (1)
3 Replies
Or
MVP
MVP

You would typically add this as a field in your load script, making it easily reusable across the entire app.

Evan0211
Creator
Creator
Author

I did the following:

SET _DateCheck = if([date] > Today, 'Future', 'Past');

And then I set a pie chart to _DateCheck and did the measure as a Count([ID]).

Now, I want to do a custom color on the pie chart like this:

Custom Color Expression: If(_DateCheck = 'Future', Blue(), Red())

but it is changing the entire pie chart to Red()

I have also tried 

If(Pick(_DateCheck , 'Future'), Blue(), Red()) but it still colors the entire pie chart red instead of just the past slice.

Or
MVP
MVP

Set creates a variable, not a field, and it does not evaluate the expression (you would need Let for that). You also incorrectly used Today instead of Today().

You would typically do this as a field in the load statement, e.g.

Load Date, if(Date > Today(), 'Future','Past') as isFuture, SomeOtherField

From SomeTable;