Summing the value of the aggregate function Last() - sum

enter image description hereI am trying to design a report in ssrs that returns the last opening stock for each product in the dataset. To achieve this I used
=Last(Fields!CustProdAdj_new_openingstockValue.Value).
This works fine. But where I encountered a problem is in getting the sum of all the opening stock for each product. I tried using
=sum(Last(Fields!CustProdAdj_new_openingstockValue.Value))
but I got the error message
[Error on Preview]
Please is there another way to go about this
I have tried using aggregate(), runningValue(), to no avail
This is the dataset
This is the report layout
On previewing having used max()

This is probably easier to do directly in the dataset query but assuming you cannot change that, then this should work...
This assumes your data is ordered by the CustProdAdj_createdon column and that this is a date, datetime or some other ordered value, change this bit if required.
=SUM(
IIF(Fields!CustProdAdj_createdon.Value = Max(Fields!CustProdAdj_createdon.Value, "MyRowGroupNameHere"),
CustProdAdj_new_openingstockValue,
0)
)
Change the MyRowGroupNameHere to be the name of the rowgroup spelled exactly as it is in the rowgroup panel below the main design panel. Case sensitive and include quotes.
What this does is, for each row within the rowgroup "MyRowGroupNameHere", compare the CustProdAdj_createdon date to the max CustProdAdj_createdon across the rowgroup. . If it is the same then return the CustProdAdj_new_openingstockValue else return 0.
This will return the value required on only 1 record within the group.
For example, if you had 1 row per day then only on the last day of the month would a value be returned other than 0 because only the date of the last record would match the maximum date within the group.
Then it simply sums the results of this up.

Related

Serial Numbering an SSRS Table with Grouping And Headers

[Report Design]
Here is an Example for a report that I am working on.
It is grouped by "CostCenter" Field and above each group there is a header with the SUM of the "Betrag" Field.
I want to Number each Column in the Table with the Headers as well.
I tried using RowNumber(Nothing) or Row Number("DataSet") Or Running Value.
I get these results [Report View]
I think there should be a way or a Formula that connects both Fields in the Colmun Row Number or "Zeilennr" that results with a Correct Row Numbering for each Row
You can almost do this. The number would not work if placed to the left of the inner group, it needs to be at the same level as the details group but it will give you the correct number. I've only done very limited testing but it seems to work.
Go to the report's properties and then to the code tab.
Now add the following custom code function
Public rn as Integer
Public Function GetRn() AS Integer
rn = rn +1
return rn
End Function
Now in the text box where you want the number to appear use the expression
=Code.GetRn
All this does in increment the public variable by 1 then return it. It has no concept of the row it lies on, so if you did not include this on a group row, the numbers would remain sequential.
Here is a demo based on a small test report I had..
Design showing the position of the expression
Gives this result
Add the same expression to more text boxes...
Give these results...

count only if field has one entry in Tableau

I am using tableau and am stuck in making the field of the following code unique.
"COUNTD(
IF NOT(ISNULL([firstBillingDate]))
THEN [msisdn]
ELSE NULL
END
)"
Basically its counting unique msisdn's for all the columns which have firstbillingDate present (NOT NULL).
The problem is that one msisdn has more than one firstBillingDate. I want to count unique msidns which has only ONE firstbillingdate
Instead of using [firstBillingDate] in that calculation, create an LOD calc to only retrieve one date per msisdns.
{fixed [msisdns] : min([firstBillingDate]}
You can use max or min. I assumed you'd want min to return the earlier date for any multiple dates per msisdns. Now use this in your original calc.

SSRS how to use multiple criteria in expression - based on a row value and a field name

Please look at the image below, my dataset has two processes, 'logs processed' and 'stacked at kilns'.
I need to take the total 'stacked at kilns' and divide it by the total 'logs processed' for each length.
so for example for field name 5.4 (dataset field length), I would like to divide 2784/2283 to return a percentage of the recovery.
my expressions currently is
=Sum(IIf(
(Fields!process.Value = "Logs Processed") AND (Fields!Length.Value=Fields!Length.Value)
, Fields!cubes.Value
, Nothing)
, "Wetmill_to_Kiln")
But this returns the value of all lengths where process is 'Logs Processed' not for just length 5.4 as per example.
So each length field is dynamically created (3.3,3.6,3.9 .... 6,6.3,6.6)
I would like to get the total for 'stacked at kiln'/'logs processed' for each length field.
any help appreciated as always
example of my desired output in bottom image.
current output:
Desired output:
*****UPDATE AS PER TPHE*********
I have created a text box inside the column group. this returns the value for that group but how can I reference the value of that text box.
if I use something like ReportItems!tbxSource.Value how can I reference the value of the textbox when the it is dynamically created across the column group? there are then mulitple instances of that textbox name?
with reference to the picture how do get the value of the white <> from the textbox with green <>
Thanks,
Since you are using a column group, you can put your expression into a text box within the group and it will execute on only the data that is captured within each column. So if your code for the Logs processed row is something like Sum(Logs) and your code for the Stacked at Kiln row is something like Sum(Stacked), your expression code for the recovery row would be Sum(Stacked)/Sum(Logs). The key is to make sure that it is within the column group.
So what I got to work was to create two variables on the column group. one called kilntotal and one called logtotal. the variables value was equal to the result of this expression:
=sum(iif(Fields!process.Value="logs",cdbl(Fields!cubes.Value),cdbl(`0)))`
and
=sum(iif(Fields!process.Value="kiln",cdbl(Fields!cubes.Value),cdbl(0)))
I then use these variable in my logic in my recovery % row:
=Variables!kilntotal.Value/Variables!logtotal.Value
Thanks for the input and your time.

How to Calculate specific cell total in SSRS?

As shown below image i have problem to calculated specific fields total.
I want to just calculate only two cells value like
total=(total opening-qty) + (total purchase-qty) cell and opening, purchase, sales are all from Type Group.
Please tell me the Expression or tips.
It's hard to tell without seeing your DataSet/report, but the expression would be similar to:
=Sum(IIf(Fields!Type.Value = "OPENING" or Fields!Type.Value = "PURCHASE"
, Fields!qty.Value
, Nothing)
This will take a SUM of all qty values, but it will ignore any Type rows that don't match the types you're specifying, i.e. OPENING and PURCHASE.
The most import thing is to make sure the expression is in the correct Scope, i.e. if you're grouping by Type the expression should be applied outside of that group Scope to make sure the expression is considering all the required rows.

Sum of distinct values in field SSRS 2005

I'm working on SSRS report builder that is using a dataset calling a SQL Server 2000 database.
The query is getting sums of a few different fields and is also pulling out all records that have to do with that client number. I want to get the sum of the sum but it is way over because of the detail rows. Basically what I want is the sum of the distinct sum column values.
=Sum(Fields!tot.Value, "table1_Group3")
I saw that you can get sums by the groups and I tried the expression above but it comes back with an error:
The Value expression for the textbox 'tot' has a scope parameter that is not
valid for an aggregate function...
table1_Group3 is the name of the group that holds the sum value in the report.
Any suggestions on how to get the distinct values to sum them in this report.
=Sum(Fields!tot.Value, "table1_Group3")
The code above will give you the sum of "tot" for all rows in the current "table1_Group3." This means that this expression only makes sense somewhere within table1_Group3. Otherwise, SSRS doesn't know which is the current instance of that group.
Sounds like you would like to sum this value across multiple groups, but only take one "tot" from each instance of the group. (Are you sure that all rows in that group will have the same "Tot?")
If tot is the total of other fields in your returned data, then simply add those up in your formula. This may have the added benefit of simplifying your SQL query as well.
Some other options that could work:
- Change your SQL query so that only one row per group gets the Tot field set.
- Use Embedded code in the report to keep a running total which is added to only once per group, such as in the group header.
(If upgrading to 2008R2 SSRS is an option, then the Lookup function could be used here, maybe even to look back at the same dataset.)
change the query/ dataset to sum(distinct tot) using the temp table on the sql server
I suppose you need to write sum(distinct columnName).