Page 1 of 1

IF dosnt work with NUMBR

Posted: Mon Jan 16, 2017 10:36 am
by manoel.ss
Hello.

I'm creating a cube with a cell that returns "1" when the first character of the cost center equals 4 and returns "0" when it is other than 4. And I'm having problems, though it's a simple rule. The "IF" Always returns "0", even when the value is true (4).

I am making a rule using two elements:
The "first number" element returns the first character of the cost center:
['First number'] = NUMBR (SUBST (! ALL.D.CENTRO_CUSTO_UNIDADE, 1,1));

The second element brings "1" to 4 and "0" if it is not:
['Value'] = IF ('first number' = '4', 1, 0);

Anyone can help me to understand what is worng?
Thanks.

Manoel.

Re: IF dosnt work with NUMBR

Posted: Mon Jan 16, 2017 11:49 am
by Wim Gielis
The first rule appears to be correct.

The second rule should be:

['Value'] = IF( ['First number'] = 4, 1, 0);

Re: IF dosnt work with NUMBR

Posted: Mon Jan 16, 2017 11:55 am
by qml
You have syntax issues there.
manoel.ss wrote:The "first number" element returns the first character of the cost center:
['First number'] = NUMBR (SUBST (! ALL.D.CENTRO_CUSTO_UNIDADE, 1,1));
No, it doesn't. This would:

Code: Select all

['First number'] = S: SUBST ( !ALL.D.CENTRO_CUSTO_UNIDADE, 1, 1 );
manoel.ss wrote:The second element brings "1" to 4 and "0" if it is not:
['Value'] = IF ('first number' = '4', 1, 0);
And the above shouldn't even compile. This, however, should work:

Code: Select all

['Value'] = IF ( ['First number'] @= '4', 1, 0 );

Re: IF dosnt work with NUMBR

Posted: Mon Jan 16, 2017 1:11 pm
by manoel.ss
Thanks qml and Wim Gielis by the answers! Both help me to simplify my rule to:

['valor'] = N: IF(SUBST(!ALL.D.CENTRO_CUSTO_UNIDADE, 1, 1) @= '4', 1, 0);

That worked!

Manoel