SSRS Calculations with multiple datasets - ssrs-2008

I have a report with 3 datasets. Each dataset is pulling data from a different data warehouse. At the end of my report, I have a table that is getting the totals from each dataset, and I have successfully done this for normal total fields. However, there are some fields that are percentages. Below is an example of the expression I have in my text box.
I am taking the existing expression from the table with one dataset and trying to add the value from each data set so I can get a total percentage.
Field using 1 dataset
=code.SafeDividePercent(Sum(Fields!Field1.Value), Sum(Fields!Field2.Value))
Field combining all data sets
=code.SafeDividePercent(
Sum(Fields!Field1.Value, "DataSet1") +
Sum(Fields!Field1.Value, "DataSet2") +
Sum(Fields!Field1.Value, "DataSet3")
),
(
Sum(Fields!Field2.Value, "DataSet1") +
Sum(Fields!Field2.Value, "DataSet2") +
Sum(Fields!Field2.Value, "DataSet3")
)
However, when I try this I get the following error.

Try this
=code.SafeDividePercent(
Sum(Fields!Field1.Value, "DataSet1") +
Sum(Fields!Field1.Value, "DataSet2") +
Sum(Fields!Field1.Value, "DataSet3")
,
Sum(Fields!Field2.Value, "DataSet1") +
Sum(Fields!Field2.Value, "DataSet2") +
Sum(Fields!Field2.Value, "DataSet3")
)
You just had brackets in the wrong place I think.

Related

Talend : tExtractRegexFields and globalMap

My job is composed like that :
tRest >> tExtractJSonFields >> ttExtractRegexFields > (row3) > tMSSqlRow
I'm using a tExtractRegexFields compenent with 3 output variables.
The next component is a tMSSqlRow.
I would like to use tExtractRegexFields's output in my SQL query as a parameter.
My SQL Query is like that :
;WITH nums AS
(SELECT 1 AS PAGE
UNION ALL
SELECT PAGE + 1 AS value
FROM nums
WHERE nums.PAGE < "+(Integer)globalMap.get("row3.lastpage")")
INSERT INTO flight.Calendar_Page (DT_CAL, NUM_PAGE)
SELECT '2016-01-01', PAGE
FROM nums
option (maxrecursion 32767);"
"row3.lastpage" is a tExtractRegexFields's output variable.
This one is always contain NULL value.
I don't understand why globalMap.get("row3.lastpage") is null. Anyone knows how to use tExtractRegexFields's outputs ?
Thank you all
Do not use globalMap.get("row3.lastpage") in the SQL query in your tMSSqlRow, but simply concatenate row3.lastpage with your SQL string. And row3.lastpage is not a string, but row3 is a Java class in the Talend generated code and lastpage is one of its fields. This field contains the data you want to inject into the SQL statement.
globalMap.get("row3.lastpage") will always by null.
Your query should be something like:
WITH nums AS (SELECT 1 AS PAGE UNION ALL SELECT PAGE + 1 AS value FROM nums WHERE nums.PAGE < " + row3.lastpage + ") INSERT INTO flight.Calendar_Page (DT_CAL, NUM_PAGE) SELECT '2016-01-01', PAGE FROM nums option (maxrecursion 32767);

idh_hist query is very slow while searching with date

I am trying to write a query to search thru MFG/PRO invoice table 'idh_hist' for specific date range. It is running very slow when added the date condition. But when I put off the date condition, it is very fast. Can you please suggest ways to write a query on idh_hist that runs reasonably faster with conditions.
Following is my query:
for each idh_hist no-lock where idh_domain = "d0002"
and idh_due_date = TODAY:
/* display code here... */
end.
Thanks in advance!
Database Index:
Flags Index Name Cnt Field Name
----- --------------------- ---- ---------------------
idh_fsm_type 4 + idh_domain
+ idh_fsm_type
+ idh_nbr
+ idh_line
pu idh_invln 4 + idh_domain
+ idh_inv_nbr
+ idh_nbr
+ idh_line
idh_part 4 + idh_domain
+ idh_part
+ idh_inv_nbr
+ idh_line
u oid_idh_hist 1 + oid_idh_hist
You do not appear to have an index that uses idh_due_date. You will need to add such an index.
The 4gl uses rules to select indexes based on the WHERE clause. The most important rule is that leading components of the index which have equality matches will be used.
The query you have shown only has one such match on idh_domain. So then tie breaker rules are applied. This will result in the idh_invln index being chosen.
As it is, to satisfy your query all records that match the "idh_domain" field need to be searched. (If you only have one domain that means that you are doing a table scan.)
You probably want to add an index on idh_domain and idh_due_date. That would be a perfect match for your query.

Tickperplant subscription by sym sending single records not tables by editing .u.pub

I have a ticker plant that has the schema:
quote:([]time:(); sym:();expiration:();mtype:();price:();cond:();exchange:();volume:())
trade:([]time:(); sym:();expiration:();mtype:();price:();cond:();exchange:();volume:())
rfills:([]time:();sym:();expiration:();tag:();price:();volume:())
I then double check the schema by doing
meta trade
I subscribe to the tickerplant as such getting the trade table
h(`.u.sub;`trade;`)
But when I try to specify a symbol from sym by doing
h(`.u.sub;`trade;`ZB)
No records are being pushed, This is odd because when I subscribe to all syms you can see that `ZB is definitely sym being pushed as shown below after setting upd to show
Figured out the above question, as a single record was being pushed not a table or key-value pair.This is what is going on.
So I was publishing a single record not a table from qSharp:
string giantstring2 = ".u.upd[" + "`trade;" + qdatetime + "," + rsymbol + "," + rexp + "," + qtype + "," + qprice + "," + qcondition + "," + qexchange + "," + qvolume + " ]";
q.Async(giantstring2);
I then set .u.upd to be .u.pub . So clients are recieve the single record but since its not a table nor a key value pair it doesn't grab the sym. So then I decided to change .u.upd to be
.u.upd:{[tabname;tabdata]
tabname insert tabdata;
tabd1::tabdata;
r2:: last (eval tabname);
.u.pub[tabname; r2];
};
So now subscribing by sym works however there is another issue, now it keeps publishes the entire table not just the record. Thinking of how to make this do what I want however I'm not sure how to go about it. Upon investigation of the .u.pub function
{[t;x]{[t;x;w]if[count x:sel[x]w 1;(neg first w)(`upd;t;x)]}[t;x]each w t}
It looks like it goes through the table and publishes each record. I assume I can edit this to just submit the last record and everything should work how I expect it to. Although I am unsure how to that. Any ideas? I assume I need to change the each w t part to only grab the last record and not the entire table

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);

concatenate without losing thousands separator

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.