KoolReport's Forum

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

The best way for data comparison #653

Closed Eugene opened this topic on on Feb 6, 2019 - 10 comments

Eugene commented on Feb 6, 2019

Hi,

Could you recommend me how better to organize the following:

I have a table in the database,

date !  item  ! sales_amount

I need to compare the sales data for 2 different periods So the result must look like

tems      !      periode 1      !   periode   2  !    vs (periode2/periode1)
--------------------------------------------------------------------------
item1     !      100            !      200       !    2
item2     !        -            !       50       !     N/A

In terms of SQL, it is two queries to the same table but with the different date range

How to put them to the one table considering that the list of items in the results can be different (some items the same, some not)

I think I can do something like that using sql join with subselect but maybe koolreport has something easier

KoolReport commented on Feb 7, 2019

There are two ways:

  1. Create the join query as you thought. You may join at database level (with query) or at php level using Join process. If your data is large, better to use at database level.
  2. You may query all data from your table as normal, use CalculatedColumn to create new column "period" and based on the date, the new column value will be "period 1" or "period 2" based on your definition in calculatedcolumn. Basically you label your row. Then you use Cube process with "row"=>"item" and "column"=>"period" and you "sum"=>"sale_amount", you will get a table like your drawing above. Finally, you use CalculatedColumn again to calculate the difference between "period 1" and "period 2" columns.
Eugene commented on Feb 7, 2019

ok. thanks, I will try both ways :-) never used the cube process before so wanna try :-)

Eugene commented on Feb 7, 2019

Hi, one more question

I followed your recommendation and it is great :-))

But what if the task is a bit more complicated and I have the data like this

date ! item ! quantity ! sales_amount

and i need to have 2 columns for each period sum quantity and sum sale_amount. Is it possible to get with Cube?

I tryed like this but it doesn't work

"sum" => array("quantity","sales_amount")

KoolReport commented on Feb 7, 2019

I think you are looking for the SuperCube process. you may specify multiple rows, columns or sums. Please follow the instruction in our documentation.

Eugene commented on Feb 7, 2019

koolreport is like a detective novel - more interesting with each page :-)

KoolReport commented on Feb 7, 2019

I like your comparison :D, anything please let me know.

Eugene commented on Feb 7, 2019

You know

i try like this

->pipe(new SuperCube(array(
               "row" => array("category","name","uom"),
  //              "row" => "category","name","uom",
                "column" => "periode",
                "sum" => array ("quantity","total"),
            )))

And with the commented row (it is like in the documentation) I get only the first column but with the array it works nice same in the "sum".

KoolReport commented on Feb 7, 2019

it should be

"row" => "category,name,uom",

It may accept string with comma delimiter between column names or array of column names.

Eugene commented on Feb 7, 2019

:-( my mistake

Eugene commented on Feb 9, 2019

I Love Koolreport!

I can get this table

with just some lines of code. Really cool!

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
solved
testimonial

None