KoolReport's Forum

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

Calculation with different data store? #65

Open zenon opened this topic on on Aug 7, 2017 - 7 comments

zenon commented on Aug 7, 2017

Hi,

Is it possible to perform calculations with 2 different columns from two different data store, as shown below?

zenon commented on Aug 7, 2017

And how to avoid error if there is a division by zero? For example, sales = 0, transactions = 0; sales per transaction = 0.

zenon commented on Aug 7, 2017

Can the above be done with koolreport?

Thanks

KoolReport commented on Aug 7, 2017

Yes it is possible, you always can retrieve data from data store by calling $this->dataStore("name")->data(), you will receive array of associate array. Getting the sales and transaction value from two datastore, you can divide them to get what you want. Make sure to check the transaction if it has 0 value.

zenon commented on Aug 8, 2017

Could you please show me an example of the codes using CalculatedColumn?

What if the transaction has 0 value, can the report automatically display sales per transaction as blank?

Appreciate your help. Thanks.

KoolReport commented on Aug 8, 2017

Could you please post your current code here. Or you can email us.

zenon commented on Aug 17, 2017

Hi,

I have tried the above using:

->pipe(new CalculatedColumn(array(
            "salespertrans"=>function($data){
                return $data["sales"]/($this->dataStore("reportB")->data()[0]["trans"]);
            },
        )))

->pipe($this->dataStore("reportA"));

However, this resulted in errors. Could you please show me how to solve this?

Appreciate your help.

Thanks a lot.

zenon commented on Aug 21, 2017

Hi,

Sorry but could you please guide me on how to do the above?

Appreciate your help.

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