Conditionally sum in variable expression in total column - jasper-reports

I'm building a report in iReport 5.0.4, so far I have a crosstab table as follows
What I'm trying to do in Total 4 is having a total of sum3Measure but only of types "X" or "Y" (defined by the value in $V{col1}). I tried in Text Field Expression this:
$V{col1}.equals("X") || $V{col1}.equals("Y") ? $V{sum3Measure } : 0
but it returns always null. I did:
$V{col1}.equals("X") ? $V{sum3Measure } : 0
to test if the operator || is not valid but it returns null as well.
I used $V{row1} instead of $V{col1} to test it wasn't a problem different from the expression, it did the sum.
All measures are defined with Calculation type Sum
Is it possible to do what I want? if not, is there a workaround I can try?
Any help will be appreciated, if you need more info just let me know.

Related

ADF dataflow: to assign null to a negative result

I have a requirement to load null if the total hours is less than previous total hours else the difference
iif(lesser(TOTAL_HOURS, PREVIOUS_TOTAL_HOURS),null(),TOTAL_HOURS-PREVIOUS_TOTAL_HOURS)
It gives me expression could not be evaluated.
Not all rows have values for these fields, some of them are null. They are numeric fields in database.
I just want to replace negative results with null
If you look at the document iif it says
iif(<condition> : boolean, <true_expression> : any, [<false_expression> : any]) => any
Based on a condition applies one value or the other. If other is
unspecified it is considered NULL. Both the values must be
compatible(numeric, string...).
Now as per your expression:
iif(lesser(TOTAL_HOURS, PREVIOUS_TOTAL_HOURS),null(),TOTAL_HOURS-PREVIOUS_TOTAL_HOURS)
since first value you have mentioned is of type null it expects TOTAL_HOURS-PREVIOUS_TOTAL_HOURS must also return a same type null
What you can try is:
iif(lesser(TOTAL_HOURS, PREVIOUS_TOTAL_HOURS),toInteger(null()),TOTAL_HOURS-PREVIOUS_TOTAL_HOURS)
OR
case(TOTAL_HOURS < PREVIOUS_TOTAL_HOURS, toInteger(null()), minus(TOTAL_HOURS,PREVIOUS_TOTAL_HOURS) )

how to change the date format in talend

I have two scenario's,which I couldn't able to solve.
PLZ help me.
Scenario 1:
I've two files Source_1_table(Excel file),Source_2_table(Excel File).
Attached screenshot
I want to compare the source_1 date to source_2 date.
If the source_1 date is matching with source_2 date then the status should be as "Y" if not match then the status should be "N".
Here I am trying with this code row1.date.equals(row2.date)?"Y":"N"
Note:both columns are string data type.
Scenario_2:
Here source_1 SAL column have a null value.and source SAL column have a VALUE.
While I am trying to compare the source_1 sal value with source_2 sal value getting null pointerException.
I am trying with this code relation.Is(source_2.sal)?" ":source_2.sal.equals(source_1.sal)?"Y":"N"
I want to replace a value with empty space or "empty" in null value.
Please look at this snapshot.
Scenario 1: “ row1.Date.equals(row2.Date)?"Y":"N"” is working if both Source 1 & Source 2 contain dates as string.
Scenario 2: To avoid the Null Pointer Exception, check for null values before comparing Source 1 and source data. Please try the expression below:
(row2.SAL == null || row2.SAL == ("")) ? "" : row1.SAL == row2.SAL ? "Y" :"N"

Summations of values and showing result in the same row in iReport

I am using iReport designer. I have four columns in report. Value of one column will be calculated by doing sum summation and subtraction of other columns.
My result formula looks like this :
($V{cust_amount} == null ? new BigDecimal(0) : $V{cust_amount}).subtract( ($V{airlines_amount} == null ? new BigDecimal(0) : $V{airlines_amount}).subtract(($V{indi_amount} == null ? new BigDecimal(0) : $V{indi_amount}) ) )
But the result is coming just at the next row of the expected one. I am attaching a picture also.
Here the amount -15100 should come one the first row. But every value is coming just below the right row and first row is always null.
Your ternary expression seems fine - the problem is with value assignment to the variables you are using. The values are assigned after the first row is evaluated and either never change or they are assigned the same values over and over again.
You may fix value assignment to the variables but I recommend ditching the variables and using actual fields in the expression like this $F{cust_amount} - then you will be guaranteed proper value assignment before the row is printed.

String comparisons in JasperReports expressions

A database field named income_source is queried using:
SELECT * FROM table_name WHERE income_source LIKE "salaried%"
This retrieves income_source values with a "salaried" prefix. In iReport, the PrintWhenExpression value for the field is set as:
$F{income_source}.equals("Salaried")? Boolean.TRUE:Boolean.FALSE
Why does the report output differ from the SQL output?
There are a few problems:
The value "salaried%" in the SQL differs from the value of "Salaried" in the expression.
The value "salaried%" uses the % to match all text after the letter d.
There is a bit of redundancy in the PrintWhenExpression.
Try the following expression:
$F{income_source}.startsWith( "salaried" )
Or:
$F{income_source}.trim().toLowerCase().startsWith( "salaried" )
One of those should work. You will also want to ensure Blank when null is checked. Otherwise, the expression becomes:
$F{income_source} == null ? Boolean.FALSE :
$F{income_source}.trim().toLowerCase().startsWith( "salaried" )

Crystal reports sum

I need the sum of two database fields. I use this formula field :
{dbfield1}+{dbfield2}
and if dbfield1 and dbfield2 are != from null in database the sum is showing, but if the dbfield1 or dbfield2 are missing(no data) the formula field is not showing.
how can I manage this in Crystal report?
Two options :
Either use the Convert Database Fields to Null option under Report Options, which will convert the numeric field nulls to zero and make your sum work, or
Use the IsNull function in your formula :
If IsNull({dbfield1}) And IsNull({dbfield2}) Then
0
Else If IsNull({dbfield1}) Then
{dbfield2}
Else If IsNull({dbfield2}) Then
{dbfield1}
Else
{dbfield1}+{dbfield2}