SSRS custom code - reporting-services

I'm having an issue in my SSRS report. What I'm trying to accomplish is get a correct summary total for a particular group, on field ClaimNumber
How the particular formula works is based on other fields in the record, and on of those values being zero:
=iif(Fields!FieldA.Value=0,0,Fields!FieldA.Value-Fields!FieldB.Value-Fields!FieldC.Value)
So if FieldA is zero, the displayed value is 0, otherwise it displays FieldA-FieldB-FieldC.
This works fine for each individual lineitem, but the summary totals on the grouping on ClaimNumber are incorrect, as in some cases the FieldA value under that particular ClaimNumber is 0, sometimes not. So I'm having trouble summing on the ClaimNumber grouping total, as the summary does not know which records FieldA is 0, and which are not.
There must be an SSRS custom code formula that would work in this situation?

If you wrap a Sum function around your expression, or even around each individual column in the expression, it's only going to evaluate that once. In other words, this describes the issue you're having where it's not accounting for some of the rows having 0 in FieldA. One way to correct this is to make your expression a calculated field on your dataset. Then you can Aggregate the calculated field to get totals and subtotals. Since it is a calculated field, it will be evaluated row by row to get the correct total. So the good news is: no custom code!

Related

SSRS - How to create a sum (total) of an expression column?

After plenty of research, it seemd I can't find a well-explained solution to my problem. I'll join some screenshots of my Tablix, group rows, and group columns to help you to understand.
First of all, here's my tablix. It's linked to a SharePoint List.
The expressions are all like this :
=Count(Fields!ID.Value, "NameOfTheGroup")
It counts the number of elements that are filtered by one of the group chosen in the expression, and it works perfectly fine at this point.
Now, here's my groups :
They all contains filters tomanage the count precisely to the need.
What I want to do : In the last row, I want to display the sum of each column that is in a group row. But theses rows aren't datasets fields, they are just only expressions, and I can't find a way to create a proper total of each column. I heard of Running Value but the few solutions I found about it didn't work.
Thanks for the future help.
EDIT: Actually, the problem seems to be much more complex: any rows I create under my group rows are invisible : if I create a new row under the "Classification", outside the "Classification" row group, the expression I insert in the "CDI", "CDD", etc... columns stay blank. I tried with various expression or just values like "Hello World".

MS Access: How can I average a list of quantities on a report where the quantities are not zero?

I have a report. This reports returns a lot of rows. One of the columns is qty_req (quantity required). I need to AVG() this column and put the value of the average at the bottom of the report. The problem is that sometimes some rows have a zero in this column. I want the average to exclude any rows where there is a zero. How can I accomplish this?
What I've tried: I tried using DAvg in the query but it made the query time enormous.
Avg() ignores Null values. So you can use an IIf() expression to swap Null for your zero values, and then base the Avg() on that IIf() expression.
Here is the Control Source for a text box in my report's footer:
=Avg(IIf([gainOrLoss]=0, Null, [gainOrLoss]))
gainOrLoss is a field in the report's Record Source. And the text box displays the average of all those values which are neither zero nor Null.
Well then you can't use a calculated SUM() or AVG() field, simple as that.
These functions always use all rows in the report.
You need DSum() or DAvg() to calculate it separately.
If that's too slow, you need to tackle this problem.

SSRS Report - Subgroup Totals

I have an SSRS report that is currently pulling a single dataset. This dataset contains records of inventory we have. Each record is a separate asset.
I want my report to group by a certain field, and then subgroup by certain criteria that are determined with a couple different fields. Basically there is one parent group, and three adjacent subgroups. My grouping functionality is working correctly, however I am finding it difficult to add totals to each of the adjacent subgroups. When I add a total, it is totaling the specific field within the scope of the entire dataset, instead of limiting the total to just that subgroup.
How can I add totals per field within subgroup?
EDIT: Added sample data and explanation:
You can ignore the function code field, that is what I am using to group on the parent group.
asset number,description,first year,acquisition cost,function code
190,random asset,2008,5000,100
193,random asset45,2008,56000,100
197,random asset26,2014,3000,100
191,random asset27,2014,7000,100
192,random asset36,2013,15000,100
I can't seem to attach screenshots, so here goes..
In the report you can see three subgroups; Assets, AssetAdditions, AssetDeletions. In the tablix, you can see where these groups are positioned. You can also see a row directly beneath the group that is supposed to total the subgroup at the end. However, for some reason the scope is only taking into account the entire dataset. I have tried to modify the expression in the Sum function [Sum(acq_cost), "Assets"], adding in the scope parameter but then it does not allow me to even run the report. It yells at me saying that "Assets" is an invalid scope.
The easiest way I have done this in 2012 VS is to have it return as part of the data set and have it sum up the value.
For instance if you have a quantity for inventory, and you have a subset where you only want the total quantity for that set, you add another column to your dataset called TotalSetQuantity and the subtotal field will have the expression =SUM(Fields!TotalSetQuantity.Value) rather than =SUM(Fields!Quantity.Value).
You can try iif statements within your report like =sum(iif(Fields!ColA.Value=1,Fields!Quantity.Value,0) but I had some troubles getting that to work.
Hope that helps, I ran into this issue this past week and the first option worked like a charm for me.

SSRS Exclude hidden row values from total

I have a column called "Total" in SQL reporting service report.
When generating report I'm hiding some rows accoring to some formula,
But calculating the total that hidden rows values also calculating.
Can I know how to exclude hidden row value from total value?
You have two options:
Apply the same show/hide logic that you're using to hide rows to the aggregate expression.
Apply a filter at the table level.
To give an example, say I have some simple data and an associated table:
Now, say we want to hide all rows with negative values - we can do this by setting the row Hidden property as:
=IIf(Fields!val.Value > 0, False, True)
Which removes the row but doesn't change the total, i.e. what you're seeing:
We need to apply the same show/hide logic to the Sum expression:
=Sum(IIf(Fields!val.Value > 0, Fields!val.Value, Nothing))
Now the total looks better:
Taking a step back, if you want to hide rows and change totals, why not just apply a filter; in the above example this would be:
Which gives identical results without needing any show/hide logic at the row or total level.
Depending on the complexity of the expression this last option might not be applicable, but seems a bit neater to me if possible.

Exclude hidden table row from total

I've created a table with a group filter so some values stay hidden.
However, the row that shows the sum() of the above values, still counts the filtered values.
Usually I would apply the filter to the query, but I'm also using this same dataset in other tables on the same report so that's not an option.
Am I missing something here, or is this a flaw in MS Reporting Services?
This appears to be a "feature" of SSRS, apparently because it calculates values in table headers and footers before rendering the detail section of a data table.
One way around this would be to add a derived Boolean column to your dataset (assuming your data source is SQL Server, using a CASE statement or similar) showing whether the row should be excluded from the table where the filter is required.
You can then change your table filter to check the indicator, and use a expression to carry out a conditional sum to aggregate the correct total. Something like
=SUM(Iif(Fields!ExcludeRow.Value = True,0,Fields!ValueToSum.Value))
It's more of a question than answer...
How to resolve this issue if you know whether the row is hidden or not ONLY at the Row Group level?
i.e. if you're filtering on the totals by this Row Group, i.e. you cannot have a field indicating if Row is excluded or not in a dataset.
ex: I have AR Aging report which has totals per months, patients. I need to filter out negative totals per patients (Patient row group), but I have column groups as well - per month, so my dataset cannot be per-patient granularity and therefore, the only place SSRS can decide whether to hide or show the row is on the Row Group level...
I had the same issue but I had too many column totals where to enter the Iif().
I resolved it by removing the filter from the group and putting the filter into the Tablix Properties dialog box (Select Tablix, Right-click the top left corner grey box and choose Tablixc Properties).