SSRS show X amount of rows per group - reporting-services

I have a report that in which I have some grouping, I want to limit the maximum amount of rows per group to be 5.
For example: In a group of purchased items I want to show the last five purchased per category.
I've tried with Ceiling(RowNumber("GroupName")/5) as when doing page break after Nth row but I'm not quite getting the results I want. I tried in the filter group property setting the Top N but this doesn't work at all.
Is there a way at all to force RowNumber() function to equal a fix value?
I'm finding this harder than I thought it should be. I cannot modify the dataset, so I can't do this by query.
Any workaround or idea will be much appreciated

You may not be able to filter a tablix using the RowNumber function, but you can hide a row if its row number is (for example) greater than 5.
Use the *Row Visibility" properties to specify an expression like this:
=(RowNumber(Nothing) > 5)
To restart counting for every group, use the grouping name as the scope (instead of Nothing).

Related

SSRS Count Rows

I know variations of this question have been asked and I've read a lot of them but none of the solutions seem to work for me. I'm trying to get a row count or total count of only the results in one column. I can get a count using several different methods but only on the "dataset". As you can see from the image I want to count the number of rows returned for spcc_parcel. The counts I get now are wrong because I'm getting a total row count. Is it possible to just count the result rows?
Report Builder Screen Shot
This is how we count Total Records in our report
=CountRows("DataSetName")
From the question you posted, according to best of my understanding you are trying to count only those rows in which some specific column (let's say column 1) have some value,
So in order to do that you can use the following expression.
=Sum(IIf(IsNothing(Fields!Column1.Value) , 1, 0), "DatasetName")
What this expression will do is it will add 1 to the total if there exists some value in the Column name specified or otherwise add zero, after doing that with every row in the result set it will display the total in the corresponding field.
Let me know if it works.
Try this =Count("Dataset Name") or =Count("Tablix Name")

In SSRS, how do I compare a value of a parent report item with report items in a child group?

I am using SSRS 2008. I have 3 different groups above my report details that are calculated sums. I am trying to color the limit red if any of the invoice sums(A) in a child group is above the limit(B).
I am currently using this expression, but it is only looking at the first or last invoice amount. The limit report item is in a parent group just above the invoice's group.
=IIF(ReportItems!Invoice_DueDate.Value>ReportItems!Limit.Value,"Red","Black")
My Solution: I decided to use SQL to get the sum of the invoice amount grouped by due date. I then called that field in the parent group.
If I understand your question correctly, then I think you can use
=IIF(MAX(ReportItems!Invoice_DueDate.Value) > ReportItems!Limit.Value,"Red","Black")
You need some sort of aggregate function, such as MAX() to tell SSRS what the scope and operation of what should be done. (For example if you wanted to make sure the total didn't exceed the limit, you would use SUM(...)
You can reference parent groups from a child group using aggregate expressions specifying the parent group Scope.
For example, say we have some simple data:
And a simple table based on this, with a group based on grp.
Here the BackgroundColor property for the value textbox in the detail row is set as:
=IIf(Fields!value.Value > Min(Fields!limit.Value, "Group1")
, "Red"
, Nothing)
This checks all rows in the parent group of the current row, not just the current row. This works as expected:
Without knowing your data it's impossible to say if this will work in your case, but hopefully it gives you something to consider.
Edit after comments
OK, based on further comments it seems like you need aggregate on aggregate functionality.
This is available via SSRS expressions in 2008R2 and above only, so this won't help in your case.
For older versions, your best option might be to add an extra field to your Dataset that supplies the maximum Invoice value for each group, and then you can use this value without issues in the parent group.
There are some workarounds around that suggest using custom code to do this, such as this post, but I've never used this suggested solution and would only even consider it if you don't have any control over the report Dataset.

Interactive sorting in tablix with column and row groupings

I'm trying to define interactive sorting in a tablix. The sorting should affect the row order.
Attaching image of the tablix in order to explain what I'm trying to get:
I already tried to define the column header with interactive sorting and get SubjectParentID to be sorted by expression (the same expression as described bellow). The final setting I made is to apply the sorting to all groups in the tablix -
Attaching image:
The result wasn't current and the data got messed up in the cells.
Additional information: The columns are grouped by SubjectParentID. The rows are grouped by Username as parent and UserID as a child group.
The values are result of the following expression :
=iif(isNothing(Fields!ResReqCertID1.Value),
-99,
Sum(iif(Fields!CertStatusID.Value = 3
Or Fields!CertStatusID.Value = 4
Or Fields!CertStatusID.Value = 5,
1,
0)) - Fields!ResReqCertID1.Value)
In the Text Box Properties / Interactive Sorting window, change the Groups selection to the UserID group (assuming that is the most-detailed group providing the rows in your example).
This can't be done, interactive sorting cannot sort row groups by column values calculated within that group.
If you have 4 static columns you could hard code them. Then having no need for column groups interactive sorting should work as expected.
You could also define a static number, say 10, of dynamic columns, and use pivoting in the thebsql query to get columns 1-10 and their labels. Then set up 10 columns with interactive sorting on the Value_1 fields, and hide them if no data exist for that column. You could then also have an 11th column which also does column grouping but doesn't do sort if there's any chance you'll ever exc3ed the 10 columns.
You could also do this: https://www.c-sharpcorner.com/article/ssrs-interactive-sorting-on-matrix-column-group/ which is somehow even more complicated than my two solutions.
But yeah, you basically can't do this. SSRS cannot be told to sort row groups on values calculated from within the context of the column group that contained the copy of text box in which the sort button was clicked.

MySQL: Use aggregate result in further calculation

I'm currently working on writing report generators. For one report I need to do a breakdown by a given characteristic (supplier, logging user, language, etc which for each row includes the name of the characteristic I'm interested in, the number of items that match that characterastic, and the percentage of total items this figure represents. The first two aren't a problem, the third is.
For example, to get a breakdown by language I'd be using a query like this.
SELECT lang_id,
COUNT(IF(open=TRUE,1,NULL)) AS lang_total
FROM table
GROUP BY lang_id;
This gives me the number of items per language.
I can get the total number of items in the table and store it in a variable simply enough with a plain count.
SELECT #totalOpen:=COUNT(*) FROM table WHERE open = TRUE;
Now I want to add a third column, which is the figure in lang_total divided by the value in #totalOpen multiplied by 100 (in other words, the percentage of all items that fit the criteria). Something along the lines of the following:
This is the bit I'm having trouble with, as because as far as I can tell you can't use aggregate columns in calculations.
SELECT lang_id,
COUNT(IF(open=true,1,NULL)) AS lang_total
(lang_total/#totalOpen)*100 as lang_percent
FROM table
GROUP BY lang_id;
I'm sure that there must be a way of doing this in MySQL, but I've not been able to track it down. Can anyone help out with this?
I read this question now for the first time. I know that probably it's too late to be useful for you but I would have solved in this way.
select lang_id,
sum(if(open= true,1,0)) as lang_total,
coalesce(sum(if(open= true,1,null)) / #r,0) as percentage
from table,(select #r:=count(*) from table where open = TRUE) as t
group by lang_id;

Selecting total results on a report

I have a matrix with several columns and rows. Example the rows are made up of names for a company and along the top are total sales, total calls, etc. So each row will have a number under each column, and at the bottom of each column is a total for each column. Currently i have the report set up that if you click on any of the numbers it pulls up a detailed report for those particular items. But if you select the total number it brings up the results for the first row's column. Is there a way to make it return all the items details when you click the total number for that column instead of what ever the detail would be for the first row of that column? Does this make sense?
You can use the inscope function to check whether you are in the value or total row. If you are not in scope then pass the correct parameter to the details report.