How to display total sum values in summary band of groups partial sums - jasper-reports

I have a report like the image below:
Note that the sections separated by a blank space are grouped by the month and are iterated over a group band. I want to put partial in the summary band by the type of the register, like in the example figure get the sum for Register type A in January = 10, February = 5, March = 1 so as the total = 10 + 5 + 1 = 16. So the summary will look like:
How can I achieve that kind of conditional sum in jasper? Thanks in advance.

After trying a little bit with iReport I found a solution: to get the partial sum by type you have to add a variable that has the calculation type as "sum" and the reset type set as "Report". Once you set the values you have to create a variable Expression that has value only when the cell value of type is the desired value, so for the example in the question, in the column Value of the summary band in cell with the value "16" you have the expression :
$F{type}.equals("A") ? $F{value} : 0
and so on for the other types in the summary.

Related

Sum a field on UITable based on the value on dropdown

I am creating an app which will perform some simple mathematical functions. One of these functions is to sum the field on my table. However, it should sum the field based on what is selected on the drop down menu and display the sum value on an edit field component. For instance, using the attached image, when I click control total, I would like to display the sum of the numbers in the fiscal period column and display it on the edit field on the right called sum.
function ControlTotalButtonPushed(app, event)
ct = app.FieldsDropDown.Value;
total = sum(app.UITable.Data.ct);
app.EditFieldTotal.Value = total;
if total == 0
app.BalanceUnbalanceLabel.Text = 'Balance';
else
app.BalanceUnbalanceLabel.Text = 'Unbalance';
end
end
I get an error:
Unrecognized variable name 'ct'
I thought app.UITable.Data.ct would refer to the column name to sum?
Please refer to the attached picture.

How to add values to last column of a table based on certain conditions in MATLAB?

I have a 29736 x 6 table, which is referred to as table_fault_test_data. It has 6 columns, with names wind_direction, wind_speed, air_temperature, air_pressure, density_hubheight and Fault_Condition respectively. What I want to do is to label the data in the Fault_Condition (last table column with either a 1 or a 0 value, depending on the values in the other columns.
I would like to do the following checks (For eg.)
If wind_direction value(column_1) is below 0.0040 and above 359.9940, label 6 th column entry corresponding to the respective row of the table as a 1, else label as 0.
Do this for the entire table. Similarly, do this check for others
like air_temperature, air_pressure and so on. I know that if-else
will be used for these checks. But, I am really confused as to how I
can do this for the whole table and add the corresponding value to
the 6 th column (Maybe using a loop or something).
Any help in this
regard would be highly appreciated. Many Thanks!
EDIT:
Further clarification: I have a 29736 x 6 table named table_fault_test_data . I want to add values to the 6 th column of table based on conditions as below:-
for i = 1:29736 % Iterating over the whole table row by row
if(1st column value <x | 1st column value > y)
% Add 0 to the Corresponding element of 6 th column i.e. table_fault_test_data(i,6)
elseif (2nd column value <x | 2nd column value > y)
% Add 0 to the Corresponding element of 6 th column i.e. table_fault_test_data(i,6)
elseif ... do this for other cases as well
else
% Add 1 to the Corresponding element of 6 th column i.e. table_fault_test_data(i,6)
This is the essence of my requirements. I hope this helps in understanding the question better.
You can use logical indexing, which is supported also for tables (for loops should be avoided, if possible). For example, suppose you want to implement the first condition, and also suppose your x and y are known; also, let us assume your table is called t
logicalIndecesFirstCondition = t{:,1} < x | t{:,2} >y
and then you could refer to the rows which verify this condition using logical indexing (please refer to logical indexing
E.g.:
t{logicalIndecesFirstCondition , 6} = t{logicalIndecesFirstCondition , 6} + 1.0;
This would add 1.0 to the 6th column, for the rows for which the logical condition is true

Calculating dates in excel

I want to count the dates. 1 date = 1, 2 dates = 2...
I have 2 dates and I want to prepare a formula if I have 2 dates, then this is total 2.
Adjust the range references to suit your data.
=COUNTA(C2:G2)
Where C2:G2 is your first row under datum. This equation will count the number of non blank cells.
If 4.9. is a number an not text, then you could also use
=COUNT(C2:G2)
In Excel you could create a new column that checks if the cell is a date by doing =ISERROR(DAY(A1)).
If it is a date the formula will return FALSE.
Then simply count all the cells with FALSE by doing =COUNTIF(B1:B10;FALSE)
Here B1:B10 should be replaced with the cellrange of your new column that holds the true or false values

Crystal Reports -- How to show after decimal value differentnly in formula

I want to show after decimal 2 value in report but there a condition if value meet that condition then need to show full value. formula is given below but it is giving error
if trim({As400InTemp.PARTYCODE})='006883' then
{As400InTemp.SPPRIC}
else
round({As400InTemp.SPPRIC},2)
you can use MID like this:
"33.09789"
MID({yourstringhere}, 4)
or
MID(CSTR({yourstringhere}), 4)
it will return a value of 09789;

How to skip hidden rows while iterating through Google Spreadsheet w/ Google Apps Script

I have a Google Spreadsheet with many hidden rows in it, and I want to skip them when iterating through a list of rows in the spreadsheet.
It's mainly an efficiency issue, as I'm dealing with over half of my rows being hidden and in no need of being checked.
Any help would be appreciated.
New API as of 2018 that's useful for this problem: isRowHiddenByUser. See also isRowFilteredByUser.
There's no direct way of doing this in Apps Script, but there is a feature request open to provide a way get the show/hide status of a row, if you want to star it.
A workaround using SUBTOTAL. Create 2 columns A and B. A must always have a value and B has a set of formulas. These 2 columns look like this:
A | B
---------------------------
1 | =NOT(SUBTOTAL(103, A1))
1 | =NOT(SUBTOTAL(103, A2))
1 | =NOT(SUBTOTAL(103, A3))
SUBTOTAL returns a subtotal using a specified aggregation function. The first argument 103 defines the type of function used for aggregation. The second argument is the range to apply the function to.
3 means COUNTA and counts the number of values in the range
+100 means ignore hidden cells in the range.
The result of SUBTOTAL with a range of 1 cell will be 0 when the cell is hidden and 1 when the cell is shown. NOT inverts it.
Now you can read the column B with your script to know if a row is hidden.
Here's the transposed question and answer: https://stackoverflow.com/a/27846180/1385429
The issue tracker holds that request since Aug 3, 2010 with a Medium priority and just a "Triaged" status. More than 3 years and no signs of solution from the GAS team.
My workaround was to use a special leading character that would indicate the visibility state of the row/column, it is a leading backtick (`) in the cells of top header row/column.
In case if merged cells are used in column headers, then an empty top row should be dedicated just for that functionality until the google engineers will improve the API.
Same applies if there are formulas in the 1st row/column cell(s).
These dedicated rows/columns itself can be hidden.
After starting to use this functionality each show/hide column/row command should be performed from a customized menu, otherwise there'll be errors when iterating through the range programmatically, because of the missing/excessive backtick.
e.g. to hide rows of selected cells the following function is invoked
function hideSelectedRows() {
var sheet = SpreadsheetApp.getActiveSheet();
var range = SpreadsheetApp.getActiveRange();
// hide rows and add a ` backtick to the header cell
for (var row = range.getRow(); row <= range.getLastRow(); row++)
{
// add backtick only if it isn't there (that may happen when manually unhiding the rows)
var cellHeader = sheet.getRange(row, 1)
var cellHeaderValue = cellHeader.getValue()
if ( !cellHeaderValue.match(/^`/) ) {
cellHeader.setValue('`' + cellHeaderValue)
}
// hide rows of selected range
sheet.hideRows( row );
}
}
and the menu
SpreadsheetApp.getActiveSpreadsheet()
.addMenu("Show/Hide", [
{ name : "Hide Selected Rows", functionName : "hideSelectedRows" },
{ name : "Hide Selected Columns", functionName : "hideSelectedColumns" },
null,
{ name : "Hide Rows", functionName : "hideRows" },
{ name : "Hide Columns", functionName : "hideColumns" },
null,
{ name : "Show Rows", functionName : "showRows" },
{ name : "Show Columns", functionName : "showColumns" },
null,
{ name : "Show All Rows", functionName : "unHideAllRows" },
{ name : "Show All Columns", functionName : "unHideAllColumns" }
])
Once google engineers find the time to improve the onChange event, it will be possible to put those backticks automatically. Currently the changeType is limited to EDIT, INSERT_ROW, INSERT_COLUMN, REMOVE_ROW, REMOVE_COLUMN, INSERT_GRID, REMOVE_GRID, OTHER without any details on which Row/Column was inserted/removed. Looks like the team behind GAS is scanty. I wish they could hire more programmers (khm khm)
As for workaround, it is possible by using SUBTOTAL function which can returns a subtotal for a vertical range of cells.
Syntax is:
SUBTOTAL(function_code, range1, [range2, ...])
where hidden values can be skipped for any of these codes by prepending 10 (to the single-digit codes).
For example 102 for COUNT while skipping hidden cells, and 110 for VAR while doing so.
Related: Google Spreadsheets sum only shown rows at Webapps SE