Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
dana
Creator II
Creator II

A variable with IF and a parameter doesn't work

Hi People,

I created a variable to calculate a background color with the following expression:

=If($(vRepDelivYaad)=$1,vColorDarkGrey,vColorLightGrey) 

But I get the message: Error in expression.

Adding literals removes the error message, but always return the false (vColorLightGrey)

=If($(vRepDelivYaad)='$1',vColorDarkGrey,vColorLightGrey) .

Calling the variable either $(vTest(2)) or $(vTest('2')) doesn't resolve the issue.

Any Idea?

Thanks in Advance!

Labels (1)
6 Replies
Michiel_QV_Fan
Specialist
Specialist

Not sure where the $1 is referring to.

If you do this: If($(vRepDelivYaad)='2',LightGray(),LightGreen())  and you enter the value 2 in the variable in an inputbox it works as expected.

vRepDelivYaad is comparing to the value $1 that should be entered in the variable like this:

In your script:

LOAD * Inline [

KPIID, Formula

abc , Sum(Volume)

];

SET UDF_Formula = Only({1<_KPIID = {$1}>}_KPI_Formula);

In your expression: = $(UDF_Formula(abc)) will resolve to the expression Sum(Volume)

$1 is replace by abc in this exaple.

dana
Creator II
Creator II
Author

Hi,

Thanks for your suggestion..

The variable vRepDelivYaad is updated by the button, which its background color is defined by the formula:

=If($(vRepDelivYaad)=$1,vColorDarkGrey,vColorLightGrey) 

Another words, vRepDelivYaad can't be replaced by script.

 

Michiel_QV_Fan
Specialist
Specialist

What kind of  value will replace $1? your variable is comparing like 1=1

$(vRepDelivYaad) = X

dana
Creator II
Creator II
Author

Exactly!

the idea is to use one expression for all buttons.

Michiel_QV_Fan
Specialist
Specialist

Sorry, I still don't get what your goal is.

dana
Creator II
Creator II
Author

Hi,

I'll be more specific:

There are a few buttons which are used to toggle between display options: (action is update variable vRepDelivYaad)

The current choice is displayed with the black background.

Buttons.png

So instead of writing a similar background expression for  each button:

=If($(vRepDelivYaad)=1,vColorDarkGrey,vColorLightGrey) 

=If($(vRepDelivYaad)=2,vColorDarkGrey,vColorLightGrey) 

I thought of using another variable with the same expression and a parameter  , e.g., vButtonBackground:

=If($(vRepDelivYaad)=$1,vColorDarkGrey,vColorLightGrey) 

called from each button:

$(vButtonBackground(1))

$(vButtonBackground(2))

Does it make sense?

Thanks for willing to help me!