SSRS Row Group + Column Group = RowNumber Issue - reporting-services

I'm back with another SSRS question :-)
I'm dealing with survey data. I have a procedure that's returning an organization's response counts per question. So my report is defined as Group on Organization for row and Group on answer for columns. Both the number of organizations and answers are variable. That's working as expected. I've tried adding a RowCount next to the organization so that I can show rank, but the fact that each org has one row per question means that I'm getting eight rows per org.
Here's an example:
Here is my report definition:
The rank expression is currently: =RowNumber(Nothing)
Ideally, the rank would be 1, 2, 3, 4, etc... I've tried scope to the row group, column group and nothing. No help.
Any assistance would be greatly appreciated!

Had same frustrating issue; lots of time wasted. Eventually, this solution also helped:
=RunningValue(CountDistinct("YourTableName"),Count,"YourTableName")
Trick here is NOT to use the name of the group within the table/matrix, but the name of the table itself. And yes, one would think that using the table name for the scope in the function RowNumber should work, but it doesn't.

Try using:
runningvalue(Fields!AnswerText.Value,CountDistinct,"NameOfOrganizationGroup")
If its a matrix, change the name of the scope from the row scope to the matrix scope.

I do with custom code.
Add this to code section on report config:
Dim private count as integer = 0
Dim private iniRow as integer = 0
Public function nroFila(Byval rowNum as integer) as integer
if iniRow = 0 then
iniRow = rowNum
end if
if rowNum = iniRow then
count = 0
end if
count = count + 1
Return count
End function
Then, call the function in a cell inside the group:
=Code.nroFila(RowNumber(Nothing))

I seem to have found a solution, but it feels like a hack... I'm leaving this unanswered to see if someone else can provide a better solution (read less hackish).
My Rank Expression is now:
=RowNumber(Nothing)/Count(Fields!AnswerText.Value)
Everything seems to be ok. I suppose I should IIf(Count... = 0, Then RowNumber, else what I've got...

Best thing to do here, is make the Rank column equal to =RowCount()/8
Since your sure each visible row contains a total of 8 rows, this should work fine.

Add another rank column next to the existing one and put another expression in that one which takes the value from rank (rowcount?) and divide it by 8. Then make the old rank column invisible.

Are you absolutely certain that using RowNumber("NameOfOrganizationGroup") doesn't work?
Click on the matrix, click the upper-left corner selection box to select the entire thing, then right-click on the selection border and get properties. Switch to the Groups tab and look at the names of the groups in the Rows section. That's what goes in the scope of the RowNumber() function.
If you already know this and tried it, my apologies—I didn't mean to assume you didn't know. It's just not 100% clear from your question that this is not the solution.

I got it by using a windowed function in the SQL query, this counts the row correctly within the column set.
dense_rank() over (partition by mgr.employee_sk order by e.employee_sk) as row_format
where mgr.employee_sk is my Lvl 2 Row Group, and e.employee_sk is my Lvl 3 Row Group (the detail level).
Then the SSRS expression then refers to this column from the query. To avoid it aggregating I used a min function, and to avoid it not displaying for rows that don't have data in all columns of the column group I specified the scope as my Level 3 Row Group.
=Iif(min(Fields!row_format.Value, "Employee") mod 2 = 1, "white", "aliceblue")

Related

Trouble creating nested SUM IIF expression in SSRS

I am new to SSRS and have a SUM(IIF question.
My data set contains four columns: Date, GroupID, PlanPaid, and NetworkIndicator.
Here is an example of the data set:
I am trying to SUM the [PlanPaid] amount when [NetworkIndicator] = "In Network".
However, I need this amount broken up by the [Date]. I tried accomplishing this by creating the expression:
=Sum(IIf(Fields!NetworkIndicator.Value = "In Network"
, Fields!PlanPaid.Value
, Nothing)
, "Claims_Rolling12")
But this expression returns the same amount (total) across all [Dates]. How do I break it up so that it is grouped by the correct [Date]?
Here is a photo of my Tablix and my current Groups: [Tablix and Groups]
And here is a photo of the output: [Output]
You haven't said where you want this sum to appear, so the answer here might not work. If it doesn't then edit your question to show what you expect the output to look like based on your sample data.
I'm assuming here that you want to add a new column to the report that shows "In Network total" by date.
The easiest way to do this is to add a row group that groups by date, then within this group you can use a simple expression, like the one you tried, but without specifying the scope.
=SUM(IIF(Fields!NetworkIndicator.Value = "In Network", Fields!PaidPlan.Value, Nothing))
This expression will only sum rows that are within the current scope, in this case the scope will be the row group you created to group by dates.
As IO said, if this is not helpful, edit your question and show what you expect your end result to look like, based on the sample data you supplied and then I can look at it again.

SSRS Get previous value in row group

I have A tablex which has row grouping , trying to do some calculation base on the previous row in the group. so I tested Last(Fields!InQty.Value) and put it in the total cell. and it get the value of the same row :
When I tried Previous(Fields!InQty.Value) it get the value from the last row in the previous group :
so what is the way to get the previous value in the same group, also how to check if the row is the first in the group.
Thank you.
This sounds like something you could just wrap inside an IF statement, perhaps as follows:
=IIF(Previous(Fields!ItemName.Value)=Fields!ItemName.Value,Previous(Fields!InQty.Value),Nothing)
...Or replace the Nothing with some constant if it's part of a larger calculation expression.
I think the best way in SSRS to do this is to use the RowNumber value for the group the cell is in (I'm calling it "Item" in the example below), and check that the RowNumber value for the group is greater than 1 before collecting the previous value. If it isn't greater than 1 you can put Nothing in the table cell:
=Iif(RowNumber("Item") > 1, Previous(Fields!InQty.Value), Nothing)

Grouping a counted variable

I am quite new to SSRS and have what I imagine is a pretty simple question. I have the set up pictured below.
What I'm looking for is a list of dates that data exists for then a nested list of outcomes and then how many of each of those outcomes there were on that date. What I get is this,
I want 6/10/2016 > ABORT > to be 3 instead of 1 1 1. What am I doing wrong? Is it possible that I need to change my query somehow?
Try using:
=COUNT(Fields!sys_OUTCOME.Value,"sys_OUTCOME")
If you don't want to see details rows delete the Details group in the Row Groups pane.
Code Explanation:
COUNT: Returns a count of non-null values specified by the expression,
evaluated in the context of the given scope.
REFERENCE
Every aggregation function can summarize data in a given context of the given scope. In this case the scope I passed to the COUNT function is "sys_OUTCOME" group name (Row Groups) so it will return the count of sys_OUTCOME values by sys_OUTCOME group. If you don't specify the group scope it will count every row without grouping what you was getting initially.
Let me know if this helps.

How to Sum the aggregates of a child group

This should be easy, but I am stuck.
I have a table listing some figures about Qualifications - to achieve which a dataset that is essentially a row per Student is being grouped on Qualification with a Parent Grouping on "Measure" (which is just a bucket of qualifications).
One of the columns is trying to work out the number of students (well, more properly the number of students with a value in a particular field, weighted by another field) in each Measure/Qualification. In the screenshot below, it's the "Pred. Avg" column on the right hand side.
So for the Qualification Row Grouping, that column is calculated by:
=CountDistinct(Iif(IsNothing(Fields!AVG_PTS.Value) = False, Fields!Learner_ID.Value, Nothing), "Qual") * Lookup(Fields!Qual_Code.Value, Fields!Qual_Code.Value, Fields!size.Value, "DS_KS5Nationals_LKP")
This works fine - the values of 35 and 11.5 in that rightmost column are correct for those rows. What the top row should be doing is simply adding up the values in the other rows to give me the number of students in this Measure, in this case to give 46.5. To do that the expression I am using is:
=Sum(CountDistinct(Iif(IsNothing(Fields!AVG_PTS.Value) = False, Fields!Learner_ID.Value, Nothing), "Qual") * Lookup(Fields!Qual_Code.Value, Fields!Qual_Code.Value, Fields!size.Value, "DS_KS5Nationals_LKP"), "Measure")
However as you can see in the screenshot, this returns 2917 instead.
So my question is; Why doesn't that work, and given that it doesn't work how can I, within a parent group, aggregate the results of aggregates inside a child group?
EDIT:
OK so, I have determined that the following works correctly:
=Sum(CountDistinct(Iif(IsNothing(Fields!AVG_PTS.Value) = False, Fields!Learner_ID.Value, Nothing), "Qual"), "Measure")
The problem there is that the Qual row that returns 11.5 is weighted to 0.5. I.E. it actually returns 23, and the Lookup(Fields!Qual_Code.Value, Fields!Qual_Code.Value, Fields!size.Value, "DS_KS5Nationals_LKP") is for that row returning 0.5 and altering it to 11.5...so the question becomes; "how do I force that ...*Lookup(Fields!Qual_Code.Value, Fields!Qual_Code.Value, Fields!size.Value, "DS_KS5Nationals_LKP") into the "Qual" scope, like the CountDistinct() is already in?
The issue here is that you're trying to aggregate values using that Lookup function which only returns one value. There are a couple ways you could go about doing this. One option would be to use the LookupSet function to get the applicable weightings. An even better option is to combine the data in your dataset so that the weighting is available without using a lookup. That way the function can recalculate an any grouping level without you having to force a scope on it. Also, CountDistinct ignores "Nothing" so you can do without the extra IIf statement. Hope that helps.

SSRS how to get a running total of inventory amounts IN and OUT from START DATE to END DATE?

i have a stored proc returning inventory amounts between a start and end date.
the QTY field shows on-hand inventory adjustments by date, either IN or OUT.
i have a "run balance" field that needs to show the total QTY each day. if the InOut field is 0, it's QTY in. if it's a 1, its QTY out. the values reflected in In and Out are coded that way.
EXAMPLE. if i start on 4/1/14 with 5216. then 1061 of product is made on 4/1/14 i need the run balance to take 5216 and add 1061 on the next line. the next line should read 6277 instead of 1061. then if some is shipped, take 6277 and subtract, and so on.
i tried the running value on QTY, but it just repeats the QTY. doesn't calculate anything.
=RunningValue(Fields!QTY.Value,Sum,"Details")
i tried to post an image of my report preview, but i don't have the reputation ;-)
any help would be MUCH appreciated.
EDIT: OK, i tried this code block:
= Switch(RunningValue(Iif(Fields!InOut.Value = 0, Fields!QTY.Value,0),Sum,"Details"),
RunningValue(Iif(Fields!InOut.Value = "1", Fields!RunBalance.Value - Fields!QTY.Value,0),Sum,"Details"))
and i am getting a 0 on the sum fields, and #Error on the subtraction fields. but, i think this is more the direction i need to go (i hope)....but i am still not getting it.
There are a couple of things to look at here.
First, you specify the Scope of "Details" in your RunningValue expression... By default this group will have no grouping value, i.e. each row in the dataset will be in its own group. Which means the RunningValue will only ever be applied to one row only. Change the Scope to "MyDataset" or Nothing, whatever is appropriate.
Secondly, you need to consider how the InOut field affects the RunningValue.
I have created a simple Dataset:
And a simple table:
The Balance expression is:
=RunningValue(IIf(Fields!InOut.Value = 0, Fields!QTY.Value, Fields!QTY.Value * -1)
, Sum
, Nothing)
You can see this changes the Scope from your original statement, and also applies a multiplier to QTY based on InOut.
Works OK for my sample data: