How to create jasper report by giving output of one query as input of another - jasper-reports

I tried using dataset. But how can I give one dataset queries output as input to another dataset.
For example, balancesheet type report view.
My first query is
SELECT column_name_one FROM table WHERE C_GL_PRIMARY='LIABILITY'
Suppose this query returns me 2 rows, like DEPOSIT,LOAN.
My second query is
SELECT colum_name_second FROM table WHERE C_GL_ONE='column_name_one'
(i did it using datagrid and is working)
for example
DEPOSIT
term deposit
pigmy deposit
LOANS
term loan
pigmy loan
Till here everything is fine but now i have one more query which need output of second query as input for this query.
select column_name_third from table where C_GL_TWO='colum_name_second'
Here i am not able to put "colum_name_second" as input becoz it this fiels is under list not in details..
My report should look like this
DEPOSIT
term deposit
new term deposit
old term deposit
pigmy deposit
ww pigmy deposit
bbb deposit
LOANS
term loan
new tem loan
current term loan
pigmy loan
pigmyloannew
Can anybody help me ...Is there any way to do it.
Thanks.

1ST-Create the Parameter in Main report query and enter the parameter value in HashMap to populate it.
2nd-Create the parameter in dataset and use the parameter in dataset query.$p{Dataset_parameter}
3rd-If you are using List component right click on then go Edit list data source then click parameter then add the parameter of dataset and configure it with Main query output attribute.
Ex-select ID,NAME from CALENDAR WHERE REGION=$P{REGION_ID}--REGION_ID main report parameter
SELECT HOLIDAY_NAME,DATE_PICKER FROM HOLIDAYS WHERE CAL_ID=$P{CAL_ID} --CAL_ID dataset
parameter.configure as per instruction above with $P{CAL_ID} with expression $F{ID}

From your description this should just be a single query:
SELECT t1.column_name_one, t2.column_name_two, t3.column_name_three
FROM table1 t1
INNER JOIN table2 t2 on (t2.C_GL_ONE = t1.column_name_one)
INNER JOIN table3 t3 on (t3.C_GL_TWO = t2.column_name_two)
WHERE t1.C_GL_PRIMARY='LIABILITY'
Then the report would be grouped to show the data exactly as in your desired report output.

Related

In tableau how to show unmatched row in my case?

I'm new to tableau.
I have a data like this.
[department]
[employee]
And I want to get employee count under 30 age per department. like this..
[my goal]
I want to show all departments (if there is no employee)
To get result, I do these steps,
make relationship of dept - emp (one datasource)
make datasource filter (emp.age < 30)
make sheet and set row as dept_no, countd(emp_no)
But I could only get like this.
[my result]
How can I get my goal..!!??
Help me!!
It is simple hereafter. Use join (instead of relationship) on the side of dept table and Take dept_no column from dept_table instead of emp_table. To do this follow these steps
double click on first added table (say emp). A join window will open (thgis differs from relationship)
add dept table and use right join
right click age convert to dimension
right click again age and convert to continuous
create filter at most 29 on age and don't forget to check include null values in the table
If you want to add all values in view. create a calc field with calculation as
INT([Age] <30)
add sum of this field to view
edit the calculation to show all nulls as 0
ZN(INT([Age] <30))

MicroStrategy - Dynamic Attribute with join

In our MicroStrategy 9.3 environment, we have a star schema that has multiple date dimensions. For this example, assume we have a order_fact table has two dates, order_date and ship_date and an invoice_fact table with two dates invoice_date and actual_ship_date. We have a date dimension that has "calendar" related data. We have setup each date with an alias, per the MicroStrategy Advanced Data Warehousing guide, which is MicroStrategy's recommended approach to handling role-playing dimensions.
Now for the problem. The aliased dates allow for users to create reports specific to the date that has been aliased. However, since the dates have been aliased, MicroStrategy won't combine "dates" as they appear to it to be different. Case in point, I can't easily put on a report that shows order quantities and invoice quantities by order_date and invoice_date as it results in a cross join.
The solution we have been talking about internally, is creating a new attribute called order_fact_date and an invoice_fact_date. These dates would be determined at runtime via the psuedo code below:
case when <user picked date> = 'order date'
then order_date
else ship_date end as order_fact_date
case when <user picked date> = 'invoice date'
then invoice_date
else actual_ship_date as invoice_fact_date
Our thinking was then, we could have a "general" date dimension mapped to both dates which would enable MicroStrategy to leverage the same table in the joins and thereby eliminating the cross join issue.
Clear as mud?
Edit 1: Changed "three dates" to "two dates".
if I have understood correctly your problem, you have created multiple dates attributes (with different logical meaning) and they are mapped on different aliases of the calendar table.
Until users use different a single fact table in their reports there is no problem, but when they use metrics/facts from sales and invoices you have multiplied results because "Order Date" and "Invoice Date" are different attributes.
Your SQL looks something like:
...
FROM order_fact a11
INNER JOIN invoice_fact a12
INNER JOIN lu_calendar a13
ON a11.order_date = a13.date_id
INNER JOIN lu_calendar a14
ON a12.invoice_date = a14.date_id
...
As usual there are possible solution, not all of them very straight forward.
Option 1 - Single date attribute
You mention this possibility in your question, instead of using "Order Date" and "Invoice Date", just use a single "Date" attribute and teach users to use it. You can call it "Reporting Date" or "Operation Date" if this makes the life easier for them.
The SQL you should get is something like:
...
FROM order_fact a11
INNER JOIN invoice_fact a12
ON a11.order_date = a12.invoice_date
INNER JOIN lu_calendar a13 -- Only one join
ON a11.order_date = a13.date_id -- because the date is the same
...
Option 2 - We need to keep the two date attributes!
Map "Order Date" and "Invoice Date" on the same alias of your calendar table. This is usually can cause problems in MicroStrategy, because two attributes will be joined together on the same look-up table [see later on this], but in your case this is exactly what you are looking for.
With this solution you should get an SQL like this:
...
FROM order_fact a11
INNER JOIN invoice_fact a12 -- Hey! this is again a cross join!
INNER JOIN lu_calendar a13
ON a11.order_date = a13.date_id -- Relax man, we got you covered.
AND a12.invoice_date = a13.date_id -- Yes, we do it!
...
This is nice, but it works only if you have description forms coming from the calendar table (this is not always the case with dates because the ID is usually also the actual value that you show on your reports). In case you don't have a join with the calendar lookup, you SQL will end up again with duplicated result:
...
FROM order_fact a11 -- Notice no join column between the two facts
INNER JOIN invoice_fact a12 -- and no other conditions will help to join them
...
For this reason if you want to keep the two attributes separate, beside mapping them on the same lookup, you should also:
Create an hidden attribute (let's call it "Date_on_fact") map it on the fact table and the calendar table and make it child of both "Order Date" and "Invoice Date".
Un-map the "Order Date" and "Invoice Date" from the fact tables.
The idea here is to force MicroStrategy to use always the SQL code always the calendar lookup table:
...
FROM order_fact a11
INNER JOIN invoice_fact a12 -- This is like the previous one
INNER JOIN lu_calendar a13 -- But I'm back to help you
ON a11.order_date = a13.date_id
AND a12.invoice_date = a13.date_id
...
The attribute "Date_on_fact" can actually be hidden and users don't need to put it in their reports, but MicroStrategy will use it to go from the parent attributes to the fact table.
Hope this can help you to get out from the mud.
We had a same problem.
We had to create a generic time hierarchy for this and connected 2 different invoice and order time hierarchies to the generic one.
It works like charm!

Create a chart using the records of certain type grouped by month, with a moving balance

I am trying to create a chart (bar or line) in crystal from one table in my database (Sage CRM).
The records are as follows
CustomerId Date Invoice Amount
1234 3/4/2013 Cust Invoice 3322.00
1234 3/4/2013 Payment 2445.00
1234 4/5/2013 A/c transaction 322.00
1234 5/6/2013 interest 32.00
1234 6/6/2013 payment 643.00
So I would like to have a report that meets the following criteria
Only records for the last 12 months grouped in month
Only invoice types of payment, invoice and interest
A moving balance that calculates all the invoice amounts ie
(when displaying the information for July 2012, the moving balance will be the total of all invoices prior to this date.
Without this field I can create the chart no problem using select expert but I am not sure now what to do)
Should I use a cross tab? if so how will I do the selection to only show the invoices I want and the the date range I want?
After spending almost a week on this problem, with a lot of help from an expert I have finally got a solution.
In order to create a amount that is the sum of all records for a company, month and invoice type since the beginning of time, while only displaying records for the last year, I have created a SQL command
Select
//All of the fields for the report,
movingBalance.Amount
from myInvoiceTable as mit
<join to any other tables for the report>
left join (
select customerID, sum(amount) as Amount
from myInvoiceTable
where Record_Type in ('Payment', 'Invoice','Interest')
and Date < {?Report Start Date}
group by customerID) movingBalance
on mit.customerID = movingBalance.customerID
where mit.RecordType in ('Payment', 'Invoice','Interest')
and mit.Date >= {?Report Start Date}
and mit.Date <= {?Report End Date}
There are a couple of tricks to using commands:
For performance reasons you generally want to include ALL of the data for the report in a single command. Avoid joining multiple commands or joining one or more tables to a command.
Filter the data in the command, NOT in the Select Expert in the report.
Create any parameters in the Command Editor, not in the main report. Parameters created in the report won't work in the Command Editor.
This has done the trick.
Create Date Parameters in the report to filter out the records at the time of fetching now when you run the report you have left with the data you need.
Now you can manuplate the data inside report using formula fields.
Accoding to me writing stored procedures is a bit hectic task as you can manuplate the data inside the report. I don't have any intentions to disrespect anyone opinions but frankly its my opinion.
In that case Rachsherry I would recommend the following.
For criteria parts 1 & 2 I think instead of using stored procs, it may be easier for you to use a formula.
For invoices right click the invoice field, then "Format Field" in the common tab next to the Suppress option there is a formula button, enter the following...
IF {YourInvoiceField} IN ["Payment", "Invoice", "Interest] THEN FALSE ELSE TRUE
For your date requirement you need to use a selection formula... The code for that should look something like this
{YourDateHere} > DateAdd ("yyyy", -1, CurrentDate) AND {YourDateHere} < CurrentDate
The above code basically looks at dates between the day the report is run, and exactly a year before.
For your moving balance, you should be able to achive that with the guide here
Edit - An alternative to this is to use parameter fields (Which I don't personally like) it just means having to input the parameters every time the report is refreshed, they are self explanatory but you can find a guide here

SSRS - Expression using different dataset fields without the "first" or "sum"

I have a ssrs report with three datasets. I would like to populate a column that shows =(Fields!Total_Hrs.Value, "Dataset3") without the "SUM(Total_Hrs)" that is showing as an option when I click on Datasets under the Category.
The problem with using =(Fields!Total_Hrs.Value, "Dataset3") is that I'm getting an error stating "Report item expressions can only refer to fields within the current dataset scope or, if inside an aggregate, the specified dataset scope."
Would one know what is causing the error? Is there a way to have the expression window show my Fields as DataSet3?
Thank you.
The problem is how is SSRS supposed to know what row you want from Dataset3? So you have two choices:
Option 1: If you want the total per person, include the total hours in your main dataset as a nested query calculation, like so:
SELECT Person, Hours, TotalHours
FROM Time
INNER JOIN (
SELECT Person, SUM(Hours) AS TotalHours
FROM Time
GROUP BY Person
) TotalTime ON Time.Person = TotalTime.Person
Option 2: If it is a genuine grand total, just have Dataset3 return one row and use an aggregate on this:
SELECT SUM(Hours) AS TotalHours
FROM Time
and use this in your expression with an aggregate:
=SUM(Fields!TotalHours, "Dataset3")

SSRS 2008 R2 - Group toggle aggregates

I'm working with a dataset where employee utilization is calculated as (Time Billed to X/Standard Billable hours). As such, to get the total billable percentage for an employee, I can just sum up the percentages billed to each client. However, I also want to be able to see the percentage of time billed by department.
I've currently got my data in a matrix with row groups Department-->Employee-->Client with 1 column group of "time sheet ending date". When I toggle the visibility of the client row group based on the employee row group, I get the correct totals at the client and the employee level. However, when I toggle the visibility of the employee row group based on the department row group, the department row group has the wrong totals. For example, if Department A has employee B with 90% utilization and employee C with 95% utilization, the toggled total at the department level is 185%....However, I am expecting to see 92.5%....any ideas????
You might just need to tweak the expression used to get the department total. I am unsure what expression exactly you used, but it should be of the form:
SUM(epmployeePercentageColumn)/COUNT(employeePercentageColumn)
obviously replace the "employeePercentageColumn" with whatever field or variable or expression that represents each of the employee percentages that come under the particular department.
If your current expression isn't in that form, try and tweak it.
Hope it Helps.