Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
william_ericksson
Contributor III
Contributor III

If Statement with logic in field

Hi All

I am trying to make a Chart If Statement work using a field to inject the logic.

Here are my test data:

Data:

LOAD * INLINE [

Value, Dimension

1, Cars

3, Bikes

];

Logic:

LOAD * INLINE [

Dimension, Logic, Target_Value

Cars, Value < Target_Value, 2

Bikes, Value > Target_Value, 2

];

In my chart, I have used the following test If statement:

if($(=Logic), 1,0)

The challenge I have is that my formula works when one of the dimensions is selected (eg Cars or Bikes):

IfStatement02.PNG

But it does not work in the default state with no selections. It only returns the dash '-' see below:

IfStatement03.PNG

Does anyone have a way to make this scenario work so that the logic works when no selections are made? File attached...

Thanks in advance,

Will

1 Solution

Accepted Solutions
tamilarasu
Champion
Champion

Hi William,

Have a look at the attached file.

If(Pick(Match(Logic,$(=Concat(Chr(39)& Logic & Chr(39), ','))),$(=Concat(Logic,','))),1,0)

Capture.PNG

View solution in original post

4 Replies
ujjwalraja
Contributor III
Contributor III

Hi,

Create a variable vTest

Capture1.PNG

Use the expression $(vTest)

You will get your output.

Capture.PNG

Thanks,

Uj

tamilarasu
Champion
Champion

Hi William,

Have a look at the attached file.

If(Pick(Match(Logic,$(=Concat(Chr(39)& Logic & Chr(39), ','))),$(=Concat(Logic,','))),1,0)

Capture.PNG

william_ericksson
Contributor III
Contributor III
Author

Many thanks Tamil -  that works brilliantly!

william_ericksson
Contributor III
Contributor III
Author

Thanks Uj - I like that idea. However, I want to keep the Logic field within the table for now. See Tamil's solution below.