concatenate without losing thousands separator - jasper-reports

I have a report that brings total sales and total probability sale.
The request was that this be shown in one table as "R"{totalamount}" (R"{totprobamount")".
So i added this together in a variable with the variable expression being
"R" + $F{Totalt} +" (R" + $F{Totalp} +")"
but by doing this the Thousands separator does not show anymore?

If you can add a field for each value you wouldn't do this with String concatenation but by using patterns on text field. add for each field in the properties panel a patter such as R #,##0.00.
if it has to be in a single field you'd need to add an expression to actually format the numbers in the desired way such as for example: "R" + new DecimalFormat("#,##.00").format($F{Totalt}) + " (R" + new DecimalFormat("#,##.00").format($F{Totalp}) + ")"

You can use the FORMAT function to have thousand separator.
FORMAT({totalamount} +{totprobamount},2)
This column become String column so you have to add this column separately , you cant use same column for integer value. Where 2 is for up to 2 decimal value.

Related

How do I get unique values of one column based on another column using the insert database query in Anylogic?

How do I get unique values of one column based on another column using the query?
I tried using
(double)selectFrom(tasks).where(tasks.tasks_type.eq()).uniqueResult(tasks.task_cycle_time_hr);
I want to automate this and make sure that all the values of task_type are being read and a unique value for each of the tasks_type is being returned!
For all the values in the column task_type, I require a unique value from the column task_cycle_time_hr.
I don't really understand why you're trying to do this in one query.
If you want to get the cycle time (task_cycle_time_hr column) for each task type (tasks_type column), just do queries in a loop for each possible tasks_type value. If you don't know those a priori, do queries for each value returned by a query of the task type values, which would look something like
for (String taskType : selectFrom(tasks).list(tasks.tasks_type)) {
double cycleTime = (double) selectFrom(tasks)
.where(db_table.tasks_type.eq(taskType))
.firstResult(tasks.task_cycle_time_hr);
traceln("Task type " + taskType + ", cycle time " + cycleTime);
}
But this just amounts to querying all rows and reading the task type and cycle time values from each, so you wouldn't normally do it like this: you'd just have a single query looping through all the full rows instead...
List<Tuple> rows = selectFrom(tasks).list();
for (Tuple row : rows) {
traceln("Task type " +
row.get(tasks.tasks_type) + ", cycle time " +
row.get(tasks.task_cycle_time_hr));
}
NB: I assume you don't have any rows with duplicate task types because then the whole exercise doesn't make sense unless you want only the first row for each task type value, or want some kind of aggregate (e.g., sum) of the cycle time values for each given task type. You were trying to use uniqueResult, which may mean you want to get a value if there is exactly one row (for a given task type) and 'no result otherwise', but uniqueResult throws an exception (errors) if there isn't exactly one row (so you can't use that directly like that). In that case one way (there are others, some probably slightly better) would be to do a count first to check; e.g. something like
for (String taskType : selectFrom(tasks).list(tasks.tasks_type)) {
int rowCount = (int) selectFrom(tasks)
.where(db_table.task.eq(taskType))
.count();
if (rowCount == 1) {
double cycleTime = (double) selectFrom(tasks)
.where(db_table.tasks_type.eq(taskType))
.firstResult(tasks.task_cycle_time_hr);
traceln("Task type " + taskType + ", unique cycle time " + cycleTime);
}
}
Import your excel sheet into the AnyLogi internal DB and then make use of the DB wizard that will take you step by step to write the code to retrieve the data you want
(double) selectFrom(data)
.where(data.tasks.eq("T1"))
.firstResult(data.task_cycle_time_hr)

How to send multiple variables using birt report?

Using the following query in db2:
select * from table where num in ('1a2334','1a43432','1a34243','1b34325','1b4545')
Now whenever I get data to report I get the rows like from the users:
1a23344
1a43432
1a34243
1b34325
1b45454
Then I use notepad++ to replace rf with ',' so it becomes
'1a2334','1a43432','1a34243','1b34325','1b4545'
What are my options for creating a report that accepts input easy enough for the average user?
This specific user has an excel sheet with multiple columns, I only use the first column (the mentioned examples above are rows from the first column).
A good solution provided by #Simulant, but I need this to get values from an excel file (preferably by copy paste). I noticed his/her solution uses static values, so I think I need dynamic values.
For the record I got the following error using the script:
Error evaluating Javascript expression. Script engine error:
TypeError: Cannot call method "replace" of null
(/report/data-sets/script-data-set[#id="12"]/method[#name="beforeOpen"]#3)
Script source:
/report/data-sets/script-data-set[#id="12"]/method[#name="beforeOpen"],
line: 0, text:
__bm_beforeOpen(). (Element ID:1) Error.ScriptEvaluationError ( 1 time(s) ) detail : org.eclipse.birt.report.engine.api.EngineException:
There are errors evaluating script "var parameters =
params["multiSelectParameter"].value; var replacesPart = "'" +
parameters.join("', '") + "'"; this.queryText =
this.queryText.replace("replaceMe", replacesPart);":
Create a Report with a Multi-Select Parameter. Create a List Box Parameter and allow multiple values. You can add static values or select dynamic and display the result of another query.
Write your query as following SQL-Statement:
select * from table where num in (replaceMe);
Select your Data-Set and select the script Tab. Enter for the beforeOpen the following script. This replaces the placeholder replaceMe in your SQL-Statement with the concatinated values of your Multi-Select Parameter enclosed with single quotes ' and separated with commas , as you need it:
var parameters = params["multiSelectParameter"].value;
var replacesPart = "'" + parameters.join("', '") + "'";
this.queryText = this.queryText.replace("replaceMe", replacesPart);

Get substring into a new column

I have a table that contains a column that has data in the following format - lets call the column "title" and the table "s"
title
ab.123
ab.321
cde.456
cde.654
fghi.789
fghi.987
I am trying to get a unique list of the characters that come before the "." so that i end up with this:
ab
cde
fghi
I have tried selecting the initial column into a table then trying to do an update to create a new column that is the position of the dot using "ss".
something like this:
t: select title from s
update thedot: (title ss `.)[0] from t
i was then going to try and do a 3rd column that would be "N" number of characters from "title" where N is the value stored in "thedot" column.
All i get when i try the update is a "type" error.
Any ideas? I am very new to kdb so no doubt doing something simple in a very silly way.
the reason why you get the type error is because ss only works on string type, not symbol. Plus ss is not vector based function so you need to combine it with each '.
q)update thedot:string[title] ss' "." from t
title thedot
---------------
ab.123 2
ab.321 2
cde.456 3
cde.654 3
fghi.789 4
There are a few ways to solve your problem:
q)select distinct(`$"." vs' string title)[;0] from t
x
----
ab
cde
fghi
q)select distinct(` vs' title)[;0] from t
x
----
ab
cde
fghi
You can read here for more info: http://code.kx.com/q/ref/casting/#vs
An alternative is to make use of the 0: operator, to parse around the "." delimiter. This operator is especially useful if you have a fixed number of 'columns' like in a csv file. In this case where there is a fixed number of columns and we only want the first, a list of distinct characters before the "." can be returned with:
exec distinct raze("S ";".")0:string title from t
`ab`cde`fghi
OR:
distinct raze("S ";".")0:string t`title
`ab`cde`fghi
Where "S " defines the types of each column and "." is the record delimiter. For records with differing number of columns it would be better to use the vs operator.
A variation of WooiKent's answer using each-right (/:) :
q)exec distinct (` vs/:x)[;0] from t
`ab`cde`fghi

Getting null fields in crystal reports

I have a customer name with first name, last name, middle name. I want to concatenate these fields. When I concatenate these fields I am getting some of the fields as null cause as it contains at least one null value field. I have tried with this formula.
{FIRST_NAME}&","&{MIDDLE_NAME}&","&{LAST_NAME}
Ex: I have first name, last name but middle name is null then I am getting entire field as null.
Please help me how to resolve this.
You'll probably want to wrap each field with a formula to adjust for nulls:
// {#FIRST_NAME}
If Isnull({table.FIRST_NAME}) Then "" Else {table.FIRST_NAME}
Then create a formula to concatenate them
// {#FULL_NAME}
{#FIRST_NAME} + "," + {#MIDDLE_NAME} + "," + {#LAST_NAME}

how can i get one value from one field (Crystal report)

I get one field V_Name from Database is"Name,StartTime:13:56,EndTime:16:56", how can i just get only one value 13:56 from it? i only want the start time under the column start time. i've tried choose(1,table.field) but it seems only take the first index Name, and the return type should be string. please suggest. Thanks
Try:
// {#end_time}
// create array from comma-delimited list
Stringvar Array values := Split( "Name,StartTime:13:56,EndTime:16:56", ",");
// extract "16:56"; convert to time
Time( Split( values[3], ":")[2] + ":" + Split( values[3], ":")[3] );
If the format of the string is always the same you can get the value between character 16 and 21. Create a formula "StartTime" and place this code there:
Mid ("Name,StartTime:13:56,EndTime:16:56",16 ,5 )
This should return 13:56
To make it a real formula replace "Name,StartTime:13:56,EndTime:16:56" with your field, it will be something like {table.V_Name}.