Grouping and sum records in JasperReport - sum

I have a list of records. All records have names, quantities and project names. Records can be duplicate in the list. I wanted to group the records by project name, so I used report group, but I also wanted to sum the same records within a project if there are duplicate ones.
Excel sheet now:
project name: 123 (in Group header)
Name Quantity (in Group header)
item1 15 (in Detail band)
item2 5 (in Detail band)
item2 7 (in Detail band)
item3 11 (in Detail band)
Excel sheet I prefer:
project name: 123 (in Group header)
Name Quantity (in Group header)
item1 15 (in Detail band)
item2 12 (in Detail band 5+7)
item3 11 (in Detail band)
I use sql query. I tried to sum up the records in sql, but then I could not group the records by project name, since all records were summed without grouping by project name.
I found this:
Grouping records in JasperReports
But this topic deals only with grouping and not summing within group
I hope someone can show how to set ireport.

I've been suffering to find answer for a week and now that I'd posted my question here, I found a solution shortly that.
In sql query "Select item.item_name, project.project_name, sum(inventory.item_quantity) ... From project, item, inventory ... Where (project.projectid = inventory.projectid) and (item.itemid = inventory.itemid) ... Group By project.project_name, item.item_name..."
Adding report group in ireport: (in Report Inspector view) right click on report and select Add Report Group > Select group by: project.project_name > next: add group header and footer.
I use Netbeans 8.2 and IReport 5.5

Related

Running total on calculated column in SQL Server

I am using SQL code to get the running total of a column which repeats itself, in my screen shot below, the column WeightedBilled is calculated and I use it on the report on group level as MAX(WeightedColumn).
Now I want to add a column that adds the values of WeightedBilled and pick up just one value of the said column.
When I use over partition by clause, it adds all repeating values.
My code is:
SUM( WeightedBilled) OVER (PARTITION BY(CheckProjID), rpt_tEmployeeName) AS EmpLevelWeightedBill`,
On the SSRS 2005 report side: the dark background is where I want the sum of the values.
Employee $2000 (this is what I need here)
Project 1 $500 (displayed as max(weightedBilled))
Project 2 $600 (displayed as max(weightedBilled))
Project 3 $700 (displayed as max(weightedBilled))
Project 4 $200 (displayed as max(weightedBilled))
[Report Layout]
You question is not that clear but assuming you want to add up the max values of a field and also assuming that you have a row group by employee called EmployeeRowGroup then the expression would look like this.
=SUM(MAX(Fields!WeightedBilled.Value, "EmployeeRowGroup"))
The row group is case sensitive and must be enclosed in double quotes.

Cognos - Conditionally hide a column, and summarise the remaining columns

I have a report with a static choice on the prompt page. The user can choose 'Full Detail', or 'Summarised'.
For a simplified example, say my report has these columns: Customer, Product, Date, Quantity, Value.
I would like to be able to show/hide the Date column based on the detail level choice, and have the Quantity and Value columns aggregate into a single Customer/Product line. I know how to show/hide the column (tying the choice variable to the column's Render Variable), but this does not do the aggregation, only makes the column invisible.
I have thought about doing a separate report page for Full Detail and Summary, but in my actual report I have a second choice box with which the user can choose a field to summarise by (e.g. Customer or Product), and the report will section-group by that field. At the moment I am doing that one per page (5 of them). Doing the detail choice the same way would mean I would need 10 pages. There is surely a better way.
Full detail:
Customer Product Date Qty Value
ABCD Things 22/10/2014 10 1.00
21/10/2014 40 4.00
23/10/2014 50 5.00
Summarised (How it looks at the moment, after hiding the Date column):
Customer Product Qty Value
ABCD Things 10 1.00
40 4.00
50 5.00
Summarised (How I would like it to look):
Customer Product Qty Value
ABCD Things 100 10.00
I am using Cognos Report Studio 10.1.1
You should not just hide column.
You should also set same value for this column in all rows
Instead of just [Date] in this column set
if (?HideDate? = 1) then ('') else ([Date])
or, if you prefer CASE
case ?HideDate? when 1 then '' else [Date] end
replace ?HideDate? = 1 with you own condition
Alexey's answer is great if you are using the standard Cognos 'auto-group and summarize' functionality.
If you have a custom aggregate that includes the [Date] column in its definition, you might squeeze a bit of performance gain out of modifying the aggregate function itself to disregard the [Date] column when a summarized total is desired.
If your aggregate function was:
total([Value] for [Customer],[Product],[Date])
..you might change this to a CASE statement like so:
CASE ?HideDate?
WHEN 1 then total([Value] for [Customer],[Product])
ELSE total([Value] for [Customer],[Product],[Date])
END
The data items after a 'for' clause usually end up in a GROUP BY clause in the resultant SQL. Limiting the items grouped, when possible, can help performance. In this case the performance improvement would likely be slight since there will only be one distinct value in Alexey's solution, but it's something to consider.

How to filter information within a Cross Tab in Crystal Reports

I am trying to create a single cross tab that includes both filtered and non-filtered data. I understand that I could do this by creating separate cross tabs in separate groups, then using filter expert on the group level, but I need the results to displayed in the same cross tab. I believe a similar solution to this might work, but am unclear on the implementation:
Crystal Reports Cross-Tab Column Totals as Variables
I am attempting to report on the frequency of known customers and walk-in customers (given a set customer number).
I have created a report with a cross tab with the following values:
Rows: AR_CUST.STR_ID (gives store number)
Columns: PS_TKT_HIST_DAT (gives purchase date)
Summarized Fields:
DistinctCount of AR_CUST.CUST_NO (gives count of unique customer numbers)
DistinctCount of PS_TKT_HIST.TKT_NO (gives count of tickets)
Embedded Summary (gives ratio of unique customers to number of tickets)
This works exactly as it should.
We have one value of AR_CUST.CUST_NO that is used for walk-in customers (we don't retain customer information for purchases using this customer number). So I want to calculate two additional cross tabs with the same information. The first would exclude all entries in PS_TKT_HIST.TKT_NO when PS_TKT_HIST.CUST_NO equals *WI (that's not a wildcard, that's the exact entry in SQL). The second wouldn't exclude *WI records, but would count each instance of a ticket under the *WI customer number as a separate customer. To clarify that, in the second report, my embedded summary in the cross tab would be:
DISTINCT_COUNT of CUST_NO when CUST_NO <> *WI +
COUNT of CUST_NO when CUST_NO = *WI
Is this possible by recording embedded summary values from the three cross tabs as variables, and then inserting those variables into a fourth crosstab?
Thanks
Tyler
I don't think you can extract the embeeded summary from 3 cross tabs and insert in 4th cross tab. May be I don't know.....
But I can suggest you one work around for this.
Since you have 3 cross tabs...
Take 3 sub reports in the main report and implement the individual cross tab in the 3 sub reports..
Implement the cross tab not by using the cross tab but by placing the recurring fields in the detail section and summary in the footer section and divide the detail sections using lines.. and make the report as exactly as cross tab.
Row Column1 | Column2 | Column3 //Group Header as cross tab columns
-------------------------------------
1 10 | 10 | 10 //Detail Section as cross tab rows
2 20 | 20 | 20 //Detail section as cross tab rows
-------------------------------------- // Lines will be line objects in crosstab
30 | 30 | 30 //Group Footer as cross tab summary
Above design will give your out exactly as corss tab.
Now from 3 sub reports take the required values using the Shared Varialbes and perform your calcultion in main subreport or another sub report as per your requirement.
For eg in subreport create like this:
Shared NumberVar x;
X:=DISTINCT_COUNT of CUST_NO when CUST_NO <> *WI +
COUNT of CUST_NO when CUST_NO = *WI
In main report
Shared NumberVar x;
x
Perform same in all sub reports.
This approach will give you cross tab output at the same time you can manuplate the calculations.
Let me know how it goes

ssrs report : Facing issues with Master detail kind of report

I need to generate a report of below format. The header repeats only per page.
ItemNr | ItemGenDesc | FulfilmentBin | onHand
-----------------------------------------------
CAP100 Capacitor FulFil1 5
binPriority | binBackup | binBackupQty | binMin | binMax
-----------------------------------------------------------------
1 bkBUSLOT2 100 1 5
2 bkBUSLOT3 150 2 6
CAP400 Transistor FulFil12 20
CAP500 Transistor FulFil14 30
binPriority | binBackup | binBackupQty | binMin | binMax
-----------------------------------------------------------------
1 bkBUSLOT5 250 5 9
My SQL output is as below
I tried to work with 2 tablix and somehow I got the output coming up in preview mode but when I export to PDF, I get blank lines between each item. I am guessing that's because the binPriority grid (detail grid) is hidden when the itemnr count <=1. Also the tablix1 row header appears for every grouping but I want row header to appear once per page.
Can anyone suggest what are the ways to generate this type of report?
Thanks.
Update 1 : Sorry CAP500 in the report should be Radiator. My typo mistake. The report should be grouped by ItemNumber and it is sorted by binPriority. So it will print binpriority=0 in the master grid and then in the detail grid it will print in the order of binPriority. The OnHand that is shown in the master grid is relevant to binPriority= 0.
You can achieve your specified layout with a single Tablix. This is fairly simple if you don't mind Columns 2-4 in your Group heading lining up with Columns 1-3 in your Detail. Since horizontal page real estate isn't really an issue (only 6 columns counting the blank column to the left of your Detail columns), I would take this route.
I'm not sure how much you know about SSRS, so forgive me if this explanation is too rudimentary. Others with less experience than you might find it helpful as well.
Right Click the Detail Row on your Tablix.
Select Add Group => Row Group => Parent Group.
Set the Group By value to ItemNumber and check the "Add Group Header" box.
This creates a Group By Column, which I would delete for your specified layout. Make sure to only delete the Column, not the Row Group.
In the Grouping Window (down at the bottom by default), right click the ItemNumber Row Group and select Group Properties.
On the Sorting tab/menu, set the Sort By value to binPriority.
Right Click your new Row Group Row on the Tablix and select Insert Row => Inside Group Above. You'll need to do this twice so you have 3 Row headings in the Row Group.
Insert 3 more columns for a total of 6 columns in your Tablix.
Put your ItemNr, ItemGenDesc, FulfilmentBin, onHand Labels and Values in the first two Rows, first 4 Columns of your Row Group.
Put your binPriority, binBackup, binBackupQty, binMin, binMax Labels in the Last Row, Last 5 columns of your Row Group.
Put your binPriority, binBackup, binBackupQty, binMin, binMax Values in the Last 5 columns of your Detail Row.

ms sql Query for POS item sales

I have a SQL question regarding POS system item sales data. In the database, there is a "Totals" table. In that table, contains various records identified by the "TtlType" field. I'm working with 2 types. Values 11, which is the Item POS Sales, and 12, which is the Item Cost Sales.
When I do my SQL Query, i'm doing something along the lines of
SELECT ItemNumber,
SUM(ItemCount),
SUM(ItemAmount)
FROM Totals
WHERE TtlType = 11
AND Date = 8/1/2012
etc.
I'd like to also include TtlType 12. How can I merge all of the data into one row?
If I change my WHERE to include TtlType 11 & 12, I get 2 seperate rows for each menu item. The first one being TtlType 11 which is the Sell Price, and the next being 12 which is the cost. BOTH TtlType use the SAME field names to record information (ItemCount, ItemAmount)
I hope i explained this well enough. When I use the GROUP BY, I still get the same results.
I'm not sure I understand your data structure fully, or the significance of ItemNumber.
However, you don't need a GROUP BY to do SUM as you already know, but including ItemNumber in your SELECT & GROUP BY will definitely cause you to have duplicate rows as it will be grouped on that column.
You shouldn't have any issues with the two SUM functions with just
SELECT SUM(ItemCount), SUM(ItemAmount) FROM Totals WHERE TtlType IN (11,12)
AND Date = 8/1/2012