JasperReports group by all - display row even if nothing returned - group-by

I am trying to get JasperReports to mimic the SQL GROUP BY ALL functionality. I am grouping by MY_BOOL which can either by 0 or 1 and I am displaying the value, and a count on the number of rows in my report. However, I want to display a row for each, even if there are 0 rows for one of the values. So for example, if my query returns ten rows, and MY_BOOL=0 for all ten, I would like to see:
MY_BOOL | COUNT
0 10
1 0
How can I accomplish this in JasperReports?

EDITED:
It sounds like you need 2 variables and no groups.
$V{MY_BOOL_0} counts all rows where $F{MY_BOOL} is 0. $V{MY_BOOL_1} counts all rows where $F{MY_BOOL} is 1. The initial value of each variable is 0, so it doesn't matter if there are zero rows with $F{MY_BOOL} = 0.
Display the 2 variables in the title (or summary or wherever) to provide your 2 "grouped" subtotals.
Note: These 2 variables don't use groups at all, but they would be compatible with groups. For example, you could calculate the MY_BOOL_0 and MY_BOOL_1 values for each month if you group on months.

Related

Crystal Report, Cross tab. Value of caculated member

Currently have a cross tab and created a calculated member that count 0 values but it doesnt count 0 instead it just count all the records.
already tried to do :
Create formula If{field} <= 0 Then{field}
using the formula created on the "Edit Value Formula" of Calculated Member
added a COUNT(formula) but this display all record count instead the count of data with 0 value within the column.
See this image
Create a formula that returns 1 for cases you need to count and zero otherwise.
Then, SUM that formula. Note this is SUM -- not COUNT.

How to get the COUNT of rows in Crystal Report

I have a data in database which gives me 8 rows based on date range out of which 5 are HCT, is there any formula in crystal report where I can get that count of those 'Abbr' ?
I am comparing HCT text from Dynamic report selection, I need to know can we create a variable which gives us count of 'Abbr'.
like for
HCT should return 5
US should return 2
RN should return 1 value.
UPDATE 1:
Here is what I am trying to do. I have secondary selection criteria as Dynamic report along with date range.
in the above example I have selected only "HCT", now even though sql data is returning 8 rows (HCT,US,RN) I need only the HCT count i.e. 5.
If I select "HCT" and "US" in the secondary criteria then I should get count of both HCT and US i.e. 5 + 2 = 7.
if I am not selecting anything then it should return 0, so irrespective of the data from DB, the value should be summed based on selection of my criteria.
am I clear enough?
Use Running Totals.
Specifically, make a Distinct Count running total for each Date Range code. You can set a formula in the Running Total Wizard to only evaluate records where, for example, {DateRange} = "HCT"
I found the solution for my question, I am just putting it here so that someone may help for the above mentioned formula.
This is what I did
Created a Formula(not running totals) by name SumOfSkills
if({Command.GlobalSkillAbbr} in {?GlobalSkill}) then 1 else 0
here Command.GlobalSkillAbbr is my "HCT" and '{?GlobalSkill} will contain all Global skills.
and used another formuala to sum it up.
Sum(SumOfSkills)
which gives me desired output.

Column Grouping Does Not display Duplicates

I have created a report in SSRS R2. The report is using tablix and column wise grouping.
The result set of the matrix is working fine as expected except that the consecutive same column values(or duplicates) are not getting skipped in display. Whereas my SQL is working perfectly displaying all data.
eg: sql Result set
1
1
2
3
Tablix Display (instead of) Tablix Display
1 2 3 (instead of ) 1 1 2 3
If you are grouping on the field that returns that data, then it removes duplicates by design - that's the point of grouping.
You would need to group by a different field, or just have no grouping on the tablix and only the Details region.
See here for more information on grouping: https://learn.microsoft.com/en-us/sql/reporting-services/report-design/understanding-groups-report-builder-and-ssrs

Displaying only the last of a sequence in Crystal Reports

I have a report that will occasionally have more than one detail record in a group. In such a case I only want to display the last in the sequence. I have a sequence number associated with each record so I need to suppress all detail rows in the group other than the one with the maximum sequence number.
I've tried using a global variable to recalculate the max value as of each detail record but I haven't been able to write a formula that, while printing, can use this maximum sequence number to suppress the row if it does not contain a value equal to the max sequence number.
From what i understand you have data organized by this:
Data1 Data2 SeQuencenumber
1 a 1
2 b 1
2 c 2
2 d 3
And from what i understand your want your output look like (group by Data1):
Data1 Data2 SeQuencenumber
1 a 1
2 d 3
To do so you need to write formula in detail section which compares your current detail sequence number and count of all for that group (Data1). Right-click your detail section and write formula here
Formula looks like :
if {SequenceNumber} = count ({SequenceNumber},{Data1}) then true
else false
Hope it helps, if you have any further questions feel free to ask.
try like this:
Shared Stringvar array concatenate;
concatenate:=concatenate+CStr(Sequencenumber);
now in suppress condition of details:
Shared Stringvar array concatenate;
if Maximum(concatenate)=Sequencenumber
Then false
else true
I had tried a solution similar to the one from KuKeC but with the maximum function instead of count. But while reviewing the KuKeC solution I finally saw that I was already suppressing the detail band when a date in the detail did not match a parameter date, yet the maximum function was giving the max of all data whether displayed or not.
So I first needed to add a formula field that would return the sequence number only if the data date matched the parameter date
if {PSLRegister.PSLRPPStartDate} = {?PP_Start_Date} then
{PSLRegister.PSLRSeqNo}
else
0
then I used this formula field in the equation to suppress the detail record
Maximum({#SeqIfDateMatch}, {TrnsltEmployee.TSEmployeeID}) <> {PSLRegister.PSLRSeqNo}
Thanks to all

Return 0 value if Details duplicated

I need your help in creating crystal report.
I have a formula in details section that computes working time.
How do I make the value return 0 if it is duplicated?
Here's the scenario
Name Time (Hours:Minutes)
John 1:20
........ 3:30
........ 3:30
Total Hours -> ?
My problem is I dont want to use the duplicated values (3:30) like shown above. I want a total hours for 4:50.
you have two options:
check the option in Database tab.. Select Distinct Records so that duplicate records will be eliminated.
If you don't want to use the first option then to calculate use Running Total so that you sum only those that are distinct...
Create running total something like Do sum only after change of time value
You can use the function "previous" to compare the current value with the previous value, but it works only with fields.
But i am not sure if i understood, you may be more precise about your question.
1) make a formula called "hours" or some other name
if not isnull(previous({Result.Time}) and {Result.Time} = previous({Result.Time}
then 0
else {Result.Time} /* you have to assure the same return type */
2) let the "total hours" be a sum of the formula "hours"
Note that it will work only if the rows are ordered by hours.
The result is the same of using a running total fields as purposed by Siva.