SSRS Calculations with multiple datasets using clng function - ssrs-2008

I have a report with 3 datasets. Each dataset is pulling data from a different data warehouse but all pulling the same data. 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.SafeDivideVariance(Sum(CLng(Fields!TP_Sales_Retail.Value)),
Sum(CLng(Fields!LY_Sales_Retail.Value)))
Field combining all data sets
=Code.SafeDivideVariance(
Sum(CLng(Fields!Field1.Value, "Dataset1")) +
Sum(CLng(Fields!Field1.Value, "Dataset2")) +
Sum(CLng(Fields!Field1.Value, "Dataset3")) +
,
Sum(CLng(Fields!Field2.Value, "Dataset1")) +
Sum(CLng(Fields!Field2.Value, "Dataset2")) +
Sum(CLng(Fields!Field2.Value, "Dataset3"))
)
However, when I try this I get the following error.
"The value expression for the textrun contains an error: [BC30198] ) expected.
Error
UPDATE I have added two fields one with the code
=Sum(CLng(Fields!TP_Sales_Retail.Value), "Dataset1") +
Sum(CLng(Fields!TP_Sales_Retail.Value), "Dataset2") +
Sum(CLng(Fields!TP_Sales_Retail.Value), "Dataset3")
and the other with
=Sum(CLng(Fields!LY_Sales_Retail.Value), "Dataset1") +
Sum(CLng(Fields!LY_Sales_Retail.Value), "Dataset2") +
Sum(CLng(Fields!LY_Sales_Retail.Value), "Dataset3")
I am getting the following error
The value expression for the text box 'Textbox11' has a scope parameter that is not valid for an aggregate function. The scope parameter must be set to a string constant that is equal to either the name of a containing group, the name of a containing data region, or the name of a dataset.
I get the same error even if I just try
=Sum(CLng(Fields!TP_Sales_Retail.Value), "Dataset2")
UPDATE 2.0
Here is the report design, dataset 2 and 3 are the same as dataset1 but they look at the respective data sources.
Report design 1
Report design 2
Report Design 3
The first 3 tables are looking at an individual data source. The last table is looking as dataset1 but I am summing the totals of all 3 in each field.
Report Layout

I can't test this right now but try the following
=Code.SafeDivideVariance(
Sum(CLng(Fields!Field1.Value), "Dataset1") +
Sum(CLng(Fields!Field1.Value), "Dataset2") +
Sum(CLng(Fields!Field1.Value), "Dataset3") +
,
Sum(CLng(Fields!Field2.Value), "Dataset1") +
Sum(CLng(Fields!Field2.Value), "Dataset2") +
Sum(CLng(Fields!Field2.Value), "Dataset3")
)
It's the out aggregate function (SUM in your case) that needs the scope specifying I think. Your original code had the scope as part of the CLng function
Update
I can't actually see anything wrong. I've tested with some sample data and it works as expected.
I suggest you add 2 textboxes to show the results of each value that you are passing to your custom function. It may be that there is an issue there. e.g. the first textbox would have the vaule expression set to
=Sum(CLng(Fields!TP_Sales_Retail.Value), "Dataset1") + Sum(CLng(Fields!TP_Sales_Retail.Value), "Dataset2") + Sum(CLng(Fields!TP_Sales_Retail.Value), "Dataset3")
Make sure that the values you see here are what you expect.
If this does not work then please EDIT your question and show some sample data so I can reproduce the issue. As it stands, it is working as expected.

The dataset was typed incorrectly and not matching my actual dataset name. The S in set needed to be a capital.
=Code.SafeDivideVariance(
Sum(CLng(Fields!Field1.Value), "DataSet1") +
Sum(CLng(Fields!Field1.Value), "DataSet2") +
Sum(CLng(Fields!Field1.Value), "DataSet3") +
,
Sum(CLng(Fields!Field2.Value), "DataSet1") +
Sum(CLng(Fields!Field2.Value), "DataSet2") +
Sum(CLng(Fields!Field2.Value), "DataSet3")
)

Related

Talend - How to get tFlowToIterate size and tFileInputRegex size?

Good day,
I have component tFileInputRegex and tFlowToIterate to read data from a text file, I saw there are number of row record being process as follow:
Which is 3412 rows, may I know how can I get this value in tJava_2 ?
currently I am using _NB_LINE but getting null:
System.out.println("total is " + (Integer)globalMap.get("tFileInputRegex_1_NB_LINE"));
System.out.println("total2 is " + (Integer)globalMap.get("tFlowToIterate_2_NB_LINE"));
In your example, tJava_2 executes within the iteration, i.e. once for each row. In that component, you can use globalMap.get("tFlowToIterate_2_CURRENT_ITERATION").toString() to get the number of rows processed so far. Please note that instead of casting it to Integer you need to convert it to a string as shown above in order to output it the way you do.
If you need the total number of rows, you can use globalMap.get("tFileInputRegex_1_NB_LINE").toString() - but it is only available after the end of the loop, which means the component where you access it needs to be connected to tFileInputRegex_1 via OnSubjobOk trigger.

Tableau -Calculated field for matching values based on criteria in a different column

I am trying to create a calculated field based on three conditions .
I have two columns names " source system names" which has only two values 302 and 202 only and other column name "unique ID have different numerical values .
I want to create a calculated field which will display the data as shown in "calculated field display " column. I need some help to write a logic on this .I have not done something like this before in tableau .Can someone help me out .I have around 0.5 million rows so need a logic that would work for this size of data .
Please refer attach image for a clear picture of what iam doing .
202 RECORD ONLY - when unique ID does not exists in row having source system as 302 .(example row 1,3 and 4)
302 RECORD ONLY - When unique ID does not exists in row having source system as 202.(example row 9,11 and 12)
EXISTS in both 302 and 202 - when unique ID is same for source system names 302 and 202 .(2 and 10 , 5 and 8 and 6 and 7)
Kindly help me to create a calculated field with this logic .
I tried CASE and IF function ,but i was not able to do it .
for easy understanding refer the 4th column in the attached imageenter image description here
If the 'Source System Names' has only 2 values you could create the following calculations to do what you want (assuming all the fields are strings, if they're integers this will still work with some simple changes):
Max: Source System Name
{FIXED [Unique ID]: MAX([Source System Names])}
Min: Source System Name
{FIXED [Unique ID]: MIN([Source System Names])}
Calculated Field Display
IF [Min: Source System Name] != [Max: Source System Name]
THEN 'Exists in Both 302 and 202'
ELSEIF [Max: Source System Name] = '202'
THEN 'Exists in 202'
ELSEIF [Max: Source System Name] = '302'
THEN 'Exists in 302'
ELSE
NULL
END
Hopefully that helps!

SSRS Math Ops Report Body..Aggregat functions can only

I'm really struggling to find out the proper approach to adding (or other math operations) in the report body. Surely this is a daily operation done by report writers all over the world but I'm missing the boat.
I can add etc. fields from a dataset such as SUM(Fields!FieldA + Fields!FieldB).
However when I try to work with two textboxes in the report I get the Aggregate functions can be used only on report items....blah. For example SUM(ReportItems!Textbox1 + ReportItems!TextBox2).
So how does one add two textbox values on the report body????
JB
You should be able to use =ReportItems!Textbox1.Value + ReportItems!Textbox1.Value without the Sum, assuming you're just adding values that have already been aggregated in the original textboxes.
It's hard to say without being able to see where the textboxes are in the report and what underlying values they're displaying.
You can also consider using the exact same underlying functions in the source textboxes, e.g. if textbox1 is the total of value1 in DataSet1 and textbox2 is the total of value2 in DataSet2, you could use something like:
=Sum(Fields!value1.Value, "DataSet1") + Sum(Fields!value2.Value, "DataSet2")

How to retrieve data from related past records

I am using Filemaker Pro 12. I want to create a student report that contains results from previous terms. For example, each year there are 4 terms. The report in term 1 contains only the result of term 1. But in term 2, the report contains the results from both term 1 and term 2. This continues until term 4 (end of year) which the report will contain the results from term 1 to term 4.
I created 4 fields ca1_percent, sa1_percent, ca2_percent and sa2_percent in the Results table. My Results table contains all the records of the past results. My relationship graph is shown in the diagram below:
My problem is that I kept obtaining the records (mark_percent) from CA1 only. My fields calculation is shown in the diagram below:
Can anyone help me?
Update:
The result I obtained from above is shown in the picture below. I have populated upto term 3 results.
Just a thought - might an ExecuteSQL() query to fetch the related ids as a value list, then plonking them into a id-1, id-2, id-3 be more flexible?
I solved the problem myself.
Since Filemaker just take the first matched record by default, what I did is to use GetNthRecord(SA1_Results_Match::mark_percent,2) to get the marks for SA1, using 3 to get the marks for CA2 and 4 for SA2.
My TO only need be matched by overall_percent_match which is a calculated field using year & " " & subject & " " & _kf_studentID.

SSRS - Expression using different dataset fields

I have a report with multiple data-sets. Different fields from different data-sets are used in different locations of the report.
In one part of the report, I need to do a calculation using fields from two different data-sets. Is this possible within an expression?
Can I somehow reference the data-set the field is in, in the expression?
For example, I'd like to do something like this:
=Fields.Dataset1.Field / Fields.Dataset2.Field
You can achieve that by specifying the scope of you fields like this:
=First(Fields!fieldName_A.Value, "Dataset1") / First(Fields!fieldName_B.Value, "Dataset2")
Assuming A is 10 and B is 2 and they are of type numeric then you will have the result of 5 when the report renders.
When you are in the expression builder you can choose the Category: Datasets, your desired dataset highlighted under Item: and then double click the desired field under Value: and it will appear in your expression string with the scope added.
Using same logic you can concatenate two fields like so:
=First(Fields!fieldName_A.Value, "Dataset1") & “ “ & First(Fields!fieldName_B.Value, "Dataset2")
As PerPlexSystem writes, asuming you only want to compare the first value from a dataset with values from another dataset, you can use the First function.
However, if you want to compare the values of each row from one dataset with with the values from each row of another dataset, then you will need to use a subreport - see here for further details.
Another option is to use a parameter as a variable. This is helpful if you want to create a calculated field in one of the datasets. This is best applied when the parameter value comes from a dataset with a single record.