KoolReport's Forum

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

Calculation using two Datastores #1160

Closed Ardan Peddell opened this topic on on Nov 17, 2019 - 2 comments

Ardan Peddell commented on Nov 17, 2019

Hi, I'm trying to get the result of dividing two dataStore results to use on a SimpleCard. Would appreciate some direction as not sure how get the desired result.

SimpleCard::create(array(

      "title"=>"Average Spend",
      "value"=>($this->dataStore("grossSales"))/($this->dataStore("coversQty")->sum("Pax")),
      "preset"=>"warning",
  ));

The above code does not work. The "grossSales" and "coversQty" contain only one value.

Alternatively, what would be the way to create a third dataStore from the calculation of the first two and then pas the result to the view.php file

Many thanks

KoolReport commented on Nov 18, 2019

Hi,

The $this->dataStore("grossSales") will return a datastore so you need to make a sum of a column within that grossSale dataStore for example:

$this->dataStore("grossSales")->sum("saleColumn")

or you can use the get() function get get any value from dataStore:

$this->dataStore("grossSales")->get(0,"saleColumn") // Get value at row 0 and "sale" column
Ardan Peddell commented on Nov 19, 2019

Many thanks for the pointer. I'll try that.

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
None yet

None