KoolReport's Forum

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

Two one colums queries as a table #2147

Open George opened this topic on on Jun 16, 2021 - 6 comments

George commented on Jun 16, 2021

Hi,

I have two queries in my report that each one returns one column of values related :

1st query : Month names

2nd query : values from relevant months

And i want to display them on one table using month names as headers and values like that :

Jan ,  Feb, Mar, Apr, etc
Jan Value ,Feb value , Mar value,  etc 

I've seen a couple of posts from people trying to do something similar such as : topic #381

but I don't want to create a new array , I want to use query1 for table header and query 2 as the data (or if that is not possible to create two tables with the relevant data one top of the other without headers) .

Is it possible ? George

Sebastian Morales commented on Jun 17, 2021

George, how do you match the 2nd query result with the month names? Rgds,

George commented on Jun 17, 2021

Hi Sebastian

it's the same query actually , the first time I get the months that have values and the second time I count the sum of values:

SELECT
-- MONTHNAME (itd.DateOfShippment) AS Month
COUNT(itm.Name) AS Operations
FROM ImportMaster itm
INNER JOIN ImportDetails itd on itm.ID  = itd.IDMSTR 
WHERE itd.Marketer IS NOT NULL 
AND itm.Trade LIKE "%TEXT%"
AND itd.DateOfTranshippment between '2020-08-29' and '2020-12-31'
GROUP BY MONTH(itd.DateOfShippment)

The first query returns the month names (remove comment from MONTHNAME and comment COUNT and the second as shown above returns the sum of the relative items. (that was the most elegant way I found to get the two items that I'm interested about , don't know if that's not correct, the values for dates are coming from input fields on the report page and I'm going to add the LIKE clause also on an input field later on).

Thanks

KoolReport commented on Jun 17, 2021

You should make 1 query to return both Month and Operations like this:

MonthOperations
Jan200
Feb300
......

And then you pipe through the Transpose2 process.

This will turn your table to

JanFeb...
200300...

Then you store it to datastore and finally display result using table in the view

George commented on Jun 21, 2021

Thank you I've managed to make my query return the correct data and with Transpose2 works perfect . Is there a way to name c0 to Month (or any other name) as in query ? no w it returns :

c0 Jan Feb Mar Apr May
Operations 100 200 300 400 500 

Thanks anyway

KoolReport commented on Jun 21, 2021

That's great. You may use the ColumnRename to rename column. Or if you want to remove that column, you use RemoveColumn process.

George commented on Jun 21, 2021

Thanks !! perfect

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
solved

None