Get Row Count in SSRS Report Builder - reporting-services

I have built a report using Report Builder 3.0 (that uses SQL Server 2008 R2). Now i wish to now how many records are being fetched from database to the report?
This is possible either by count function in SSRS or by using RANK/ROW_NUMBER function in SQL Query and assigning that as field to the report (RANK/ROW_NUMBER would give us rank to each row and navigating to last page in report would help me getting the total row count).
I tried count function but that counts on some field in the report. For instance = Count(Field!FieldName.value, "DataSetName") Problem in this approach: "FieldName" is not unique in the report and hence the counts get repetitive
Second option: Added Rank/Row_Number but they too use the same kind of fieldName and hence here too the counts get duplicated.
Main Problem: There is no field in my query that is unique (and hence i tried ROW_NUMBER())
How can i find the total row count or rank (for each row) in SSRS 2008?

Use the CountRows function. For example
=CountRows("MyDataset")
will give you the number of rows in MyDataSet.

As someone else mentioned above, I couldn't get CountRows("DatasetName") to work in the header until I wrapped it thusly:CSTR(CountRows("DatasetName")).

In the Tablix control's properties, there's a property name called NoRowsMessage put your message here when no row is returned.

you can't put aggregation values into the detail wihtout grouping.
Solution is below:
=Count(Fields!rn.Value)
I use it inside the column/header row.

I found a workaround for this. First create a data column with the value always set to 1. This will provide a value of one for each row of data.
Query Column
, 1 AS Unit
Use the "RunningValue" function into your report as shown below.
=RunningValue(Fields!Unit.Value,Sum,"DataSet")
This will also work as a 'running sum' if that's something you're looking for.

Related

How to customize TaxReport_IT - report SSRS?

I would like to custom the Report SSRS TaxReport_IT, I need to add a new field in order to use in to SyntethicReport Design.
(for example)
The classes involved seems these:
TaxReport_IT
TaxReportDP_IT
TaxReportController_IT
TaxReportContract_IT
Tables involved:
TmpTaxReport_ITSummary
TmpTaxReport_IT
TaxReportTmp_IT
Are there others? Are there some Queries involved?'
I added the new fields in to table _TmpTaxReport_IT_, and I pupulated the related tables
I'm sure, in to the method I pupulated correctly the new Field (I have the values ​​that I expect), but when I print the Report I get a lower value. Seems like I don't take the total data set.
How can I add the new field and take the correctly total value?
I saved the data (about my custom field in a RegularTable) and the sum is correct, but I have mismatch when I print the report.
I think I skip some step to Report DataSet.
I use Dynamics AX 2012.
Thanks in advice!
I have an idea what could be wrong, but I'm making some assumptions. If they are not correct, please edit your question to clarify.
From your screenshot, it looks like you want to add your new custom field in the header section of the report design. I'm assuming the expression of that field looks similar to
=First(Fields!MyCustomFIELD.Value, "TaxReportDS_IT")
Note the First key word in that expression. This indicates that the value for that field should be taken from the first of the records of the report's dataset.
I'm assuming that you calculate the value of the field while the records in table TaxReportTmp_IT are being created so that each record has a different value. Maybe it is a sum of some other field, so the first record would have the smallest value and the last record the highest.
If all those assumptions are correct, you can fix this by changing the First keyword to Last. This indicates that you want to take the value of the last record of the report data set.
See also the documentation of the Last Function.

SSRS Pass parameter / Field value from 1 table to another

I am using SSRS 2012.
I have two datasets. I have two tables.
The first table contains a contract Id which is used as parameter in the second dataset.
I want to set the parameter as the contractId (ie Fields!ContractId.Value, or ReportItems!Contract1.Value) or something like that but nothing works because of different limitations.
If I would be using a subreport that would have been easy just pass the Field!Contract.Value from the 1st dataset as the parameter for the second and there you go. But since we want to call the report using SQL server agent, I cannot use subreport since the agent is limited and does not accept subreport.
So I believe my only option is to use two different tables, but I still need the value from the first dataset. Also, I don't think LookUp() would work for me as I do not have Ids.
Does anyone already did something like that?
Thanks for any help.
You can create report parameters in which the available values are pulled from a query.
Then just use the parameter in your second data set.

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.

Reporting services, sum all rows of a column

I'm using reporting services 2005, I have a report with a table(table1) which displays data from an sql database.
A column on the table displays numbers. I want the total of all rows for that column, on a textbox(textbox3)
of another table(lets call it table2).
I tried placing this on a table2 textbox: =Sum(ReportItems!textbox1.Value)
texbox1 is the one from the table1. But when going to the Preview tab i get:
Error 2 [rsAggregateReportItemInBody] The Value expression for the textbox 'textbox3' uses an aggregate function on a report item. Aggregate functions can be used only on report items contained in page headers and footers.
How can I solve this?
Thanks.
You've got a couple of options.
The first is to use an expression similar to the following in the Textbox:
=Sum(Fields!value.Value, "Values")
Where Values is the name of the DataSet you want to aggregate.
Here you're creating an aggregate expression and specifying the scope where it executes, in this case a DataSet, i.e. aggregate all values in the DataSet.
As you can see from the error you're getting you can reference a report item with an aggregate, but if you're displaying the aggregate in the table header or footer you can reference that Textbox.
Here's a simple report showing both methods:
Hopefully you can adapt one method to your report.

SSRS set last row as default value for multi-value parameter

I guess that's easy... I have a multi-value parameter that got the list of values from a query. I would like to select as default value the last row.
Can I achieve this using a expression? I would like to avoid creating a second query just to get the last value from the previous query...
In the default parameter expression you can't refer to the field of the dataset, so you can't write something like Last(Field!MyVar.Value, "DataSet1"), as a workaround you can order your dataset to retrive last row as first and use "Get values from a query" which choses first row, if you can't do this then replicate your dataset in the only one solution.
I am working with SSRS 2012 and I was using a multi select option on my report so when I chose the "Get Values from a query" I got all of the values as the default.
I did find a solution. In my report I needed the default name of the town to be the first one so I created another set with the name of the column and a calculated measure that said "[DimTahanot].[Tahana Name].&[אילת]" and filtered it by the same one. (Please ignore the different language). Although hard coded it was good for this report. You could create another hidden parameter for this set if you need it to be the first one by amount or any other parameters that should effect this value, using the filter as a parameter.
Hope this helps.