KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

How to use if else statement in KoolReport? #58

Open tee opened this topic on on Aug 4, 2017 - 4 comments

tee commented on Aug 4, 2017

Hi,

Could i use if else statement in data processing of CalculatedColumn? Example:

if ('variable1' == '0')
{ 
    'new_variable'=1;
}
else
{
    'new_variable'='variable2'/'variable3'*100;
}

KoolReport commented on Aug 4, 2017

You do:

"new_variable"=>"({variable1}=='0')?1:{variable2}*100/{variable3}";
zenon commented on Aug 26, 2017

Hi,

I have done the below for nested if else statement.

->pipe(new CalculatedColumn(array(
            "a"=>"({target}+{amount}=='0')?0:({target}=='0')?100:{amount}/{target}*100",
        )))

However, I still get an error message: Division by zero, although it is stated clearly that if target + amount = 0, then 0.

Where did I do wrong?

Appreciate your help.

Thank you very much.

KoolReport commented on Aug 26, 2017

You may try this to see how:

"a"=>"({target}+{amount}==0)?0:(({target}==0)?100:({amount}*100/{target}))"
zenon commented on Aug 26, 2017

Yes, it works.

Thanks a lot.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

None