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

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.

Related

MS Access Sum and IIF expression

I'm with a non-profit. We divide the state up into 16 regions for administrative purposes. I'm trying to find out how many members live in each region. We have 4 different types of members too. There's a table that lists all the members. There is also a table in which we have listed all the towns in the state and put in which of our regions the town is in. For the first member type the record has the value "1" in the TYPE field. I'm trying to write an expression that basically says this. If the TYPE field has a "1" in it, then the condition is true, return 1. Else return 0. Then sum up all the ones.
I didn't build the database or the query. This is the expression that was already there: INDIVIDUAL: Sum(IIf([Membership.TYPE]=1,1,0)) The sum that it comes up with just doesn't make sense.
Edit: I hope I did this right. Here is a table showing what information the query returns except for the 502 and the 96 which I put there as a check. The values in that one column add up to 502 but they should add up to 674. The 96 should be 113.
enter image description here

I'm trying to aggregate a measure in Power BI Report Builder and getting nowhere

I am working on a sample project in Power BI Report Builder. (I couldn't tag it as such because apparently I'm not allowed to create my own tags on this website.) The measure I am going for in my data cube is called Direct_Claim_Deductible_Recoverable_End_of_Year, but we will call it "Deductible" because that's too long a name to type out every time. I am trying to divide it up by the fields of State, City, and Year.
The Category column tells you whether each row is for a state or a city within that state. The Year and Location columns tell you the year and location that the row is telling you about. The Deductible column shows that measure. The Pct% column formula is Deductible - Total. (I added the Total column because I was having trouble with the Pct% column and wanted to know what was going on.)
Here's where the problem begins.
The Total column is supposed to tell me what the total deductible is for that specific year. But instead, it just gives me the grand total for all years in the cube. I've run the report enough times to know that this number is $99,669.71.
Here is the formula I am using for the Total column:
=round(Sum(Fields!Direct_Claim_Deductible_Recoverable_End_Of_Year.Value),2)
The Pct% column is giving me wrong answers too, but it is based on the Total column, so fixing the Total column should also fix the Pct% column.
And the data bar is supposed to show me what percent of the total for that year is in that state's row, or what percent of the total for that state is in that city's row. Instead it gives me an error message saying I am missing a closing parenthesis ')' somewhere:
The Maximum expression for the chart 'DataBar2' contains an error: [BC30198] ')' expected.
Here is the code I used:
=(Sum(Fields!Direct_Claim_Deductible_Recoverable_End_Of_Year.Value) / (Sum(Fields!Direct_Claim_Deductible_Recoverable_End_Of_Year.Value), "StateDS"))
As you can see, all three sets of parentheses are opened and closed.
I did figure out that if I move all the parentheses to the end, like so:
=(Sum(Fields!Direct_Claim_Deductible_Recoverable_End_Of_Year.Value) / (Sum(Fields!Direct_Claim_Deductible_Recoverable_End_Of_Year.Value, "StateDS")))
I resolve that error message but get a different one:
The ValueAxis_Primary.Maximum expression for the chart 'DataBar2' has a nested aggregate that specifies a dataset scope. Inner aggregates cannot specify a dataset scope.
It seems to be telling me that I cannot have the denominator of the fraction for the City data bar specify that its scope is the dataset "StateDS", which is the dataset that aggregates by State alone. But I am confused. I don't understand why that would be. And I don't understand what I need to do to make it aggregate by state anyway.
Thank you.

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...

In SSRS is there a way to make a Row Group expand based on parameter value?

I've got a table with 5 columns, the first 3 of which allow the user to drill down through the levels of detail. Each of these columns (Region, Country & Office) has an associated Parameter so the user can select the geographic region for their report. Each parameter allows the selection of multiple values.
If the user selects 1 Region, 1 Country and 1 Office it's not exactly ideal for them to then have to expand each selection. Is there an expression I can enter somewhere to state that if only 1 value is entered in a parameter then that data set will automatically show as expanded?
This is in SSRS 2008 R2 if that makes any difference.
In the Group Properties for the detail group you can enter an expression for the initial visibility. Right now you probably have that set to "Hide." The expression needs to return a Boolean and could be something like:
=Parameters!Country.Count <> 1
This will have SSRS hide those rows if more (or less) than one value are selected in the parameter Country
But I have seen some unexpected results with this: test thoroughly. In my experience, BIDS handles these better than SSRS itself, so just when you think you've got it all working, it fails miserably once deployed. (Reason number 14 to have a test folder on production SSRS.)