How to Calculate specific cell total in SSRS? - sql

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.

Related

Summing the value of the aggregate function Last()

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.

Qlikview conditionally hide expression in pivot table

Struggling with a way to hide an expression on certain rows in my pivot table below. Basically, I want to be able to hide my expression 'Cumulative' when the FINANCIAL_PLAN_TYPE is not equal to 'OB_VARIANCE_TO_T1'. I figured out a way to change the text format on the lines with other FINANCIAL_PLAN_TYPE so that it appears hidden (what is showing in the picture below), but I'd really like the whole row to go away in these cases.
Additionally, I do not want to see a Total on the Cumulative lines if possible, but I do want to keep them on the Sum(AMOUNT) lines.
My expression for Cumulative is:
sum(aggr(Rangesum(above(sum({<YEAR={"$(vYear_Current)"},FINANCIAL_PLAN_TYPE={"OB_VARIANCE_TO_T1"}>}AMOUNT),0,MONTH_NUM)), FINANCIAL_PLAN_TYPE, MONTH_NUM))
I tried to use the function Only, as well as, I tried conditionally enabling/disabling the expression but I can't seem to get it to work. Any ideas would be great. Thanks!
FINAL SOLUTION:
1) Load Inline Table
Load * Inline
[MyDim
Cumulative
Vals
];
2) Created calculated dimension to combine the two desired dimensions into one and show blank ('') in cases that you don't want to show (this leaves one blank line on the pivot but there is probably a way to hide that too):
=If(MYDim='Cumulative' and FINANCIAL_PLAN_TYPE='OB_VARIANCE_TO_T1','Orig Budg Cumulative Variance',if(MYDim='Cumulative' and FINANCIAL_PLAN_TYPE='LE_VARIANCE_TO_T1','LE Cumulative Variance',if(MYDim <> 'Cumulative',FINANCIAL_PLAN_TYPE,'')))
3) Create a new expression that does one calculation in the case of your made up dimension = Value A and something else in case your calculated dimension = Value B
If(MYDim='Cumulative' and (FINANCIAL_PLAN_TYPE='OB_VARIANCE_TO_T1' OR FINANCIAL_PLAN_TYPE='LE_VARIANCE_TO_T1'),If(ColumnNo()=0,'',sum(aggr(Rangesum(above(sum({<YEAR={"$(vYear_Current)"}, DEPARTMENT={"20820"}, ACCT_TYPE={"Capital"}>}AMOUNT),0,MONTH_NUM)),
FINANCIAL_PLAN_TYPE, MONTH_NUM))),IF(MYDim='Vals', SUM({<ACCT_TYPE={"Capital"},DEPARTMENT={"20820"}>}AMOUNT)))
You cannot hide expression on some of the rows - not possible in Qlikview.
The workaround is to create a dummy floating table that holds the second column as a dimension and then use it in your chart instead of the two expressions. Then you will have one expression that says something like that :
If ( dummyField = 'Cummulative' and = 'OB_VARIANCE_TO_T1',
{Use your second expression here} ,
If (dummyField = 'sum(Amount)', {use your original first expression here}))
Regarding the Total, check out this link in the "Tricking the Pivot Table" section

SSRS Divide Sums from Different Scopes Returns 0

I have a grouped dataset. From the parent group down, the group names are:
Company > Plant > Details. In the end, I want to be able to take the sales of each plant and see what percentage it is of the entire company's sales. Let's say the company has a total sales of $500 and the sales of "Plant A" were $100 and "Plant B" sales were $400. I would image that I would need an expression at the Plant grouping level that was like:
=Sum(Sales)/Sum(Sales, "Company")
And I would get .2 for Plant A and .8 for Plant B. But if I do that, I get 0. I am at a complete loss. Any help with this would be greatly appreciated.
Additional information:
My exact setup is a little more complex than the example I gave below, but I believe the general idea still holds the same. I have a total of 6 groups:
The circled group is the equivalent of the "Plant" Group in my example. Here is the row group in my tablix for the GroupBy group (the one with the arrow pointing to it).
The expression that is circled in the picture above is the expression in question to get my percentage (right now really just a decimal, not formatted to be a percentage yet).
=sum(Fields!ActualCurrent.Value)/sum(Fields!ActualCurrent.Value, "Company")
Fields!ActualCurrent.Value is the equivalent of "Sales" in my example above. The expression above returns 0 for all groups. But yet, if I change it to
=sum(Fields!ActualCurrent.Value)+sum(Fields!ActualCurrent.Value, "Company")
It will produce the equivalent of $600 for "Plant A" and $900 for "Plant B."
I can't seem to find how it reacts as expected when adding the two sums, but produces 0 when I divide them.
It would be useful to see where are you using that expression to determine what is wrong here, but I think you can use this guide to get your desired result.
Create a tablix like this:
Note I've added Company and Plant fields as groups. Also I've deleted details group. Right click details and select Delete group and set Delete group only option.
Now in the percentage column use the following expression:
=FORMAT(
SUM(Fields!Sales.Value,"Plant")/SUM(Fields!Sales.Value,"Company")
,"P2"
)
The sum of every plan divided by the sum of the whole company group. It is not necessary but I am using FORMAT function to format the float value returned by the expression to percentage format using two decimal places.
It should show something like this:
UPDATE: Try scoping the sum to your specific group: GroupBy
=sum(Fields!ActualCurrent.Value, "GroupBy")/sum(Fields!ActualCurrent.Value, "Company")
UPDATE 2: Format the cell to show decimal digits.
Use thiss expression:
=FORMAT(
sum(Fields!ActualCurrent.Value, "GroupBy")/sum(Fields!ActualCurrent.Value, "Company"),
"F2"
)
It will format the value returned by the expression as a float with two decimal digits.
If you want to show the value in percentage format replace F2 in the expression for P2 (Percentage format with two decimal digits.)
Let me know if this helps.

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.

Percent of Group, not total

It seems like there are a lot of answers out there but I can't seem to relate it to my specific issue. I want to get the breakdown of yes/no for the specific Group. Not get the percent of the yes for the entire population of data.
I have tried the following code in the "What I'm Getting" % of Total cell =
=FormatPercent(Count(Fields!SessionID.Value)/Count((Fields!SessionID.Value), "Tablix1"),)
=FormatPercent(Count(Fields!Value.Value)/Count((Fields!SessionID.Value), "Value"),)
It should just be a case of changing the Scope in your expression to make sure the denominator is the total for the group, not the entire Dataset or Tablix, i.e. something like:
=Count(Fields!SessionID.Value) / Count(Fields!SessionID.Value, "MyGroup")
Where MyGroup is the name of the group, i.e. something like:
If this is still not clear, your best option would be to add a few sample rows, and your desired result for these, to the question so we can replicate your exact issue.
Edit after more info added
Thanks for adding more details. I have created a Dataset based on your example:
And I've created a table based on this:
The group is based on the Group field:
The Group % expression is:
=Fields!YesNoCount.Value / Sum(Fields!YesNoCount.Value, "MyGroup")
This is taking the YesNoCount value of each row and comparing it to the total YesNoCount value in that particular group (i.e. the MyGroup scope).
Note that I'm using Sum here, not Count as in your example expression - that seems to be the appropriate aggregate for your data and the required value.
Results look OK to me: