Finding the number of column in a table - jasper-reports

I would like to know how to tell the number of columns in a table created in iReport. The variable COLUMN_COUNT returns the number of rows, but I want to know the number of columns.
Does anyone know how to do?

The quotes from JasperReports Ultimate Guide:
BUILT-IN REPORT VARIABLES
COLUMN_NUMBER
This variable contains the current column number. For example, on a report with three
columns, the possible values are 1, 2, and 3. The variable restarts from 1 and runs up to
the defined number of columns for each page in the generated document.
COLUMN_COUNT
This variable contains the number of records that were processed when generating the
current column.
PAGE_NUMBER
This variable’s value is its current page number. At the end of the report-filling process,
it will contain the total number of pages in the document. It can be used to display both
the current page number and the total number of pages using a special feature of
JasperReports text field elements, the evaluationTime attribute. You can see this
happening in most of the samples. Check the /demo/samples/jasper sample for an
example.
REPORT_COUNT
After finishing the iteration through the data source, this report variable contains the total
number of records processed.
PAGE_COUNT
This variable contains the number of records that were processed when generating the
current page.
GroupName_COUNT
When declaring a report group, the engine automatically creates a count variable that
calculates the number of records that make up the current group (that is, the number of
records processed between group ruptures).
The name of this variable is derived from the name of the group it corresponds to,
suffixed with the _COUNT sequence. It can be used like any other report variable, in any
report expression, even in the current group expression, as shown in the BreakGroup
group of the /demo/samples/jasper sample).

Related

SSRS Grouping Summary - with Max not working

This is the data that comes back from the database
Data Sample for one season (the report returns values for two):
What you can see is groupings, by Season, Theater then Performance number and lastly we have the revenue and ticket columns.
The SSRS Report Has three levels of groupings. Pkg (another ID that groups the below), venue -- the venue column and perf_desc -- the description column linked tot he perf_no.
Looks like this --
What I need to do is take the revenue column (a unique value) for each Performance and return it in a separate column -- so i use this formula.
sum(Max(Fields!perf_tix.Value, "perf_desc"))
This works great, gives me the total unique value for each performance -- and sums them up by the pkg level.
The catch is when i need to pull the data out by season.
I created a separate column looks like this
it's yellow because it's invisible and is referenced elsewhere. But the expression is if the Season value = to the Parameter (passed season value) -- then basically pull the sum of each of the tix values and sum them up. This also works great on the lower line - the line where the grouping exists for pkg -- light blue in my case.
=iif(Fields!season.Value = Parameters!season.Value, Sum(Max(Fields!perf_tix.Value, "perf_desc")), 0)
However, the line above -- the parent/header line its giving me the sum of the two seasons values. Basically adding it all up. This is not what I want and also why is it doing this. The season value is not equal to the passed parameter for the second season value so why is it adding it to the grouped value.
How do I fix this??
Since your aggregate function is inside your IIF function, only the first record in your dataset is being evaluated. If the first one matches the parameter, all records would be included.
This might work:
=IIF(Fields!season.Value = Parameters!season.Value, Sum(Max(Fields!perf_tix.Value, "perf_desc")), 0)
It might be better if your report was also grouping on the Venue, otherwise you count may include all values.

Jaspersoft Studio subtotal from amount shown on group header

I have data that is "filtered" through three groups.
First group is defined by departments, second is defined by course id and third is for individual class session id (i.e. room and schedule). Also the source query is giving me the list of all students for each class session, and this causes that the other columns get repeated for every student (i.e. credits per course, total enrollment per session, total students dropped per session, total students auditing per session, etc).
When you drop any of those query counts on the report group's footer the sum is not correct. For example if we have 10 students for a session our sum is 100 enrollment. I want to count 10 enrolled students only once.
The amounts are not shown multiple times because I placed the fields on the group header. So on every group break the row of data is displayed only once.
I believe I need a custom running total and not the default created when you drag and drop the field on the group's footer.
I got something working.
On the report Outline I right clicked on 'Variables' and 'Create Variable'.
For example for the audit count I did the following:
Named my variable 'sum_au'
Value Class Name set to java.math.BigDecimal
Calculation set to Sum
Expression set to the query field for the audit total 'AU': $F{AU}
Increment Type set to [Group]GroupBy_CRN
Reset Type set to [Group]GroupBy_CrseNum
All other fields left untouched (default values)
Once this variable is created you can drag and drop it to the CrseNum Group Footer and it will add the values only once per break on the course session id (CRN).
I will reproduce this for the other values to see if this solution is consistent...

Crystal Reports: price for latest transaction

I need to create a field to put on group footer #1 that shows the latest price by customer type. The grouping is item_ID (see below). So for example if there were transactions over time with varying prices to Factories and to Retail stores, it would only show the price for the last time that item was sold for a factory(I have a separate field for retail stores). I have tried a few things but nothing is working. For example:
On the detail level:
if {TRANSACTIONS.TRANDATE} = Maximum ({#FactoryTranDate}, {TRANSACTION_LINES.ITEM_ID}) then
{TRANSACTIONS_LINES.PRICE}
FactoryTranDate is basically: if customer type = factory then trandate. Then I created a max of this on group footer #1.
This appears correctly on the transaction line but if the last transaction for that item wasn't to a factory, it will be 0 on the summary line. I tried to do a Max of that detail level field but it doesn't come up for my summary fields, I am assuming cause it gets confused upon doing a summary of a summary?
Sounds like the problem you are running into is the column of data you are trying to print in the footer has multiple rows and you can't predict where the value you want might be within those rows. So by the time you get to the footer, it only has the value held by the last row that printed.
To get around this you would want to use a few formula fields to create variables that can be used to store the value you want from the correct row when it is printed.
I would plan to use 3 formula fields. One to initialize your variable and set it to a default value of zero. Place this formula field in the header that corresponds to your footer and this will ensure the variable exists and is reset to a default value for each grouped value in this header. The formula will look something like this:
WhilePrintingRecords;
Shared NumberVar price:=0.00;
The second formula will declare the same variable again, and it will also include some logic to know when to set the value of the variable. This formula field should be placed within the section that prints the detail records for the grouping. The formula would look something like this:
WhilePrintingRecords;
If <condition to evaluate> Then
Shared NumberVar price:={TRANSACTIONS_LINES.PRICE}
I'm not entirely sure what condition you will want to evaluate here though based on the information you've provided, but I suspect it will be along the lines of if customer type = factory. However, it should be a condition that is only true when you want to capture the price of the detail record within the grouping. If you have multiple cases where it might be true, then you will want to sort them in such a way that the one you wish to capture is printed last within the group. Since you stated that it should be the last factory price, then I would sort by Transaction Date and the variable will change its value with each record that has a true condition and will only keep the price from the one with the latest Transaction Date.
The third formula field is simply for printing the value of your variable in the footer. This field will be placed in the footer section and will display the value of the variable on your report. The formula for this field will look something like this:
WhilePrintingRecords;
Shared NumberVar price;
The formula fields used in the header and details sections can be suppressed if you don't want them to print on your report, but I would recommend waiting until you have the final value printed in the footer verified before suppressing them. This will allow you to see how the value of your variable changes as the report is generated if you are not familiar already with using variable in this manner. You may also want to read up on the scope of variables in crystal reports if this is a new topic for you. My suggestions here all use the SHARED scope, but there are also LOCAL and GLOBAL scopes. GLOBAL might work better in your case, but I tend to favor SHARED in examples such as these because they have the most broad scope. LOCAL definitely will not work for you here though.

Print field from first record in a group in the group footer

I have a series of transactions that contain a receive and return date and are grouped. In the group footer, I want to print the receive date of the first record in the group and the return date of the last record in the group. I created a formula to populate only when it is the first record in the group. But if the group contains more than one record, the formula field prints out blank. If there is only one record in the group, it prints OK. I'm using SAP Business Object Crystal Reports 2013.
There are a few ways to handle this. If you were sorting by Date, (which I've just learned you aren't) you could use a Summary to find the Minimum value. You'd place it in the relevant Group Footer and it should reset each time.
But since you're not sorting them by Date, I'd try setting up a Running Total that counts the number of records in the current Group (and resets on change of group.) Then set up a Shared Variable in a Formula that gets set every time the Group Count resets to 1. Finally, put another Formula in the Group Footer which prints out the Shared Variable.
Done correctly each Group Footer will display the first date value in that Group.

How to detect if a table has rows in crystal 2008

Is there a built in crystal method to detect whether the a table in a crystal report has any rows?
I have created a sub report which has some Title text in the header and a detail line with the table info.
I want to be able to supress the title text from printing if there is nothing to print.
Also, is there any way to pass this to the "master" report so that I can suppress printing the sub report completely if there is nothing to print?
Regards
Use Count() function.
Use it with one of your data source fields.
from Crystal Reports 2008 Help:
Overloads
Count (fld)
Count (fld, condFld)
Count (fld, condFld, cond)
Count (x)
Arguments
fld is any valid database or formula field that can be evaluated by the function.
condFld is a field used to group the values in fld by.
cond is a String indicating the type of grouping for condFld. You only specify this argument when condFld is a Date, Time, DateTime or Boolean field. For more information on the valid strings for this argument, see Conditions for summary functions .
x is an array of values that can be evaluated by the function being used.
Returns
Number
Action
Enables you to count the values that appear in your report (for a specified field). For example:
If a sales report includes all orders made and the amount of each order, you can compute the total number of orders that appear on the report (a grand total count).
If you break orders into groups (for example, orders grouped by the state that they come from), you can compute the number of orders per group (in this case, per state).
If you break orders into date or Boolean groups (for example, orders grouped by the month in which they were placed), you can compute the number of orders per group based on a particular change in the date or Boolean field (in this case, per month).
If you specify a set of individual values, you can compute the number of values in the set. For information on this kind of counting, see Array summary functions .
Examples
The following examples are applicable to both Basic and Crystal syntax:
Count({orders.AMOUNT}, {orders.CUSTOMER ID})
This formula counts the number of orders in each group of orders in the Amount field (the total orders for each customer). The orders are separated into groups whenever the value in the Customer ID field changes.
Count({orders.ORDER AMOUNT}, {orders.ORDER DATE}, "monthly")
Counts the number of orders in each group of orders in the Amount field (the total orders for each month). The orders are separated into groups whenever the value in the Date field changes to a new month.
The following examples are applicable to Crystal syntax:
If Count({orders.ORDER ID}) >= 100 Then
"Congratulations on meeting your quota!"
Else
""
Prints the congratulatory message if the number of orders is 100 or more, and prints nothing if the number of orders is less than 100.
Count([1,2,3,4,5])
Returns 5. Counts the total number of values in the array.
Note: Using this function in a formula forces the formula to be evaluated at print time.
For more information on evaluation time considerations, see Evaluation Time.