CountRows expression appears multiple times within the group - reporting-services

I have a simple SSRS tablix with two fields - Age Bracket and # of deaths per age bracket (for particular condition). The report is grouped by Age Bracket and # of deaths is count of records per Age Bracket.
I'm using the following formula for # of deaths:
CountRows("Age_Bracket")
Here is the tablix in design mode:
However, in Report Preview I see this (# of death appears multiple times per the same Age Bracket):
How to eliminate duplicates, so the report will appear like this?

Related

SSRS - add percentage of total?

I am just starting out in SSRS and have a dataset that looks like the below.
I have built this in a matrix table like so
I want to show what percentage each of the rows total is of the grand total, so for the attached image I would want to show what percentage 35 (counselling calls) is of 47 (total) and what percentage Legal calls (12) is of total (47)
I have tried =Fields!Calls.Value/sum(Fields!Calls.Value) but that just gives me 100% for both?
Would appreciate any help
You need to specify the scope of your SUM() expressions.
I'll briefly explain how scopes work and then get to the answer.
SSRS always evaluates an expression based on it's scope which is usually defined by the physical location of the expression within table/matrix. As you can see from your design all 4 textboxes show the same expression, [SUM(Calls}] which in fact is actually =SUM(Fields!Calls.Value). However they give different results because the scope of each is different. The first is in the category rowgroup and the month column group for example, the second one is in the category row group but in the total month group, and so on...
OK, now to the answer !
Assumming
your rowgroup is called 'CategoryGroup` (you will see the name in the rowgroup panel under the main designer)
your dataset is called DataSet1
You expression should be
=SUM(Fields!Calls.Value, "CategoryGroup") / SUM(Fields!Calls.Value, "DataSet1")
This basically reads..
Take the sum of the call column for all rows that are within the current CategoryRowgroup and divide by the sum of the call column across the whole dataset.
Notes
The scope names must be enclosed in quote and are case sensitive
The scope names must match either a row or column group, or a dataset name exactly.
the , "CategoryGroup" scope argument can probably be omitted as this should be the scope of the textbox anyway.

Hide Empty Zero Data Points in SSRS Line Chart

I have an SSRS line chart that I need to figure out how to hide empty data points - stop the line from making markers/continuing the line where Category Group values are zero:
The values and series and groups are setup as so:
With the data looking like this:
I have tried filtering both at the chart level and the Category Group levels to filter out data that would create groups for Series 2020 and Category October/November/December, this creating or filling those points in my mind:
Where the expression is "=DateSerial(YEAR(today()),MONTH(today()), 1)" achieving the net result of filtering out data points/rows that from an incomplete month - meaning when the report would be run on 10/10/2020, only data from before 10/1/2020 should be used to generate groups.
The problem is that you are using COUNT() which will always return a value, zero if there are no records to count.
I created a simple dataset and using count of FILE_NUMBER I got this (replicating your issue) ...
The easiest way round this is to change the value expression to something like this...
=SUM(IIF(Fields!FILE_NUMBER.Value = Nothing, 0, 1))
This way we add 1 to the sum for every non-empty value and nothing if it's empty. If the total sum is still empty, by default, the chart will not plot that point.
So we end up with this...

SSRS Report - get distinct count of a string in a filtered group

I have a filtered group inside my tablix called Counties. My report is working well and produces the results of:
County PY CY Difference
Scott 141 143 2
Cape 90 98 8
North 78 88 10
I now need to obtain the distinct count of my counties. In my example, this would be 3.
I have scoured many blogs and have tried several things I have read.
I have tried using =CountDistinct(Fields!County.Value). When I put it in a line below my counties, but within the group, I get a 1 below each county name. When I put it in a line below my counties, but outside the group with =CountDistinct(Fields!County.Value, "Counties"), I get the error message "The Value expression for the text box ‘Textbox487’ 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 tried putting Cint() around it too and still nothing.
I have added a new column and used the distinct count function and got a 1 for each county. That is fine until I try to add them up in the row below. I used =Sum(ReportItems!Textbox486.Value) and got the error message "The Value expression for the textrun Textbox486 uses an aggregate function on a report item. Aggregate functions can only be used on report items contained in page headers and footers."
I have a feeling this is something that will need to be done with code. Honestly, I don't know code. I have always gotten by without it, until now.

SSRS Reporting multi value parameters

I have a ssrs report, that gives me multiple product's price. My Parameter is not drill down, I have to type in the parameters(since I have large range of product number).
Now my questions is, how can i get the last entered product ( parameter) always appear at the bottom of the report ?. This would help me where to look the latest product in the report.For example I have product numbers like:
abc-234,
abc-570,
ght-908,
Now what I want is that the latest entered product number which is ght-908 to appear at the bottom of the ssrs reports. Right now it gives me the report for the multiple product, but its all over the place and i have to squint my eyes and try to find out where my most recent entered product numbers (parameters) is. I have also tried to stop the parameters to being refreshed everytime i add a product number.
Assuming your parameter name is MyParameter, in report designer (BIDS) just drop a textbox onto report below the data (e.g. Table) and put following expression into its value's formula:
=Parameters!MyParameter.Value.Split(",")(Parameters!MyParameter.Value.Split(",").Length - 1)
it will split the parameter list and grab the last value
Update: here is the screenshot with steps:
And here is the runtime result
This expression works for me:
=Trim(Right(Parameters!Product_Number.Value
, InStr(StrReverse(Parameters!Product_Number.Value), ",") - 1))
Trim might not be strictly necessary but is useful as it will work if the values are split with spaces as well as commas, or not.
For example:
It sounds like you want to order the results of the stored procedure by the order of the product codes as they are typed into the report parameter (which is a comma separated list).
You can return the index (order) of each product code in the parameter by using the Array.IndexOf and Split functions, e.g.
If you have a report parameter called "ProductNumber" and you also have a field called "ProductNumber" returned in your dataset, the following code will return the zero-based index of the Product Number as entered into the parameter list:
=Array.IndexOf(
Split(Parameters!ProductNumber.Value.ToString(), ",")
, Fields!ProductNumber.Value
)
So if abc-234 is the first product number in the parameter list then this code will return 0. If abc-570 is the second product number in the parameter list then this code will return 1, etc.
Assuming the products are listed in a tablix, then I would set the tablix sort expression to the above, which should sort the products into the order specified in the report parameter.

Link Subreport to matrix

I have a matrix like below. years on columns and countries on rows.
Countries 2001 2002
US 100 400
UK 200 290
IR 300 89
I have a requirement of creating a subreport which shows Invoice details. When I click 100 (US-1002) on my main report I have to show all the 100 Invoices. I tried this way:
Since I am doing count for InvoiceID in matrix, I tried using Join(Fields!InvoiceID,", ") expression on the data test box action(Go to report). On the other side I created a subreport with multivalue parameter. But this approach dint work. I found that Join will not work with data rows as it expect arrays.
Later I used Join(LookupSet(1,1,Fields!Name.Value, "DatasetName")," / "). I could join the invoice ids but the problem is , this expression joins all the invoice ID in complete dataset. I just need US-2001 cell (100) invoice ids only to take to my subreport
From your description, it sounds like the easiest thing to do would be to set up the subreport to take two parameters, Country and Year, instead of trying to pass the list of invoices.
The subreport can then report all the invoices for a particular Country and Year combination.
It would be simpler to just set up the drillthrough to accept the two fields for its parameters, as above, instead of try to work out an expression for all the invoices in a particular cell's scope.