RowNumber for group in SSRS 2005 - reporting-services

I have a table in a SSRS report that is displaying only a group, not the table details. I want to find out the row number for the items that are being displayed so that I can use color banding. I tried using "Rowcount(Nothing)", but instead I get the row number of the detail table.
My underlying data is something like
ROwId Team Fan
1 Yankees John
2 Yankees Russ
3 Red Socks Mark
4 Red Socks Mary
...
8 Orioles Elliot
...
29 Dodgers Jim
...
43 Giants Harry
My table showing only the groups looks like this:
ROwId Team
2 Yankees
3 Red Socks
8 Orioles
29 Dodgers
43 Giants
I want it to look like
ROwId Team
1 Yankees
2 Red Socks
3 Orioles
4 Dodgers
5 Giants

You can do this with a RunningValue expression, something like:
=RunningValue(Fields!Team.Value, CountDistinct, "DataSet1")
DataSet1 being the name of the underlying dataset.
Consider the data:
Creating a simple report and comparing the RowNumber and RunningValue approaches shows that RunningValue gives your required results:

You can easily achieve this with a little bit of vbcode. Go to Report - Properties - code and type something like:
Dim rownumber = 0
Function writeRow()
rownumber = rownumber + 1
return rownumber
End Function
Then on your cell, call this function by using =Code.writeRow()
As soon as you start using groups inside the tables, the RowNumber and RunningGroup functions start getting some weird behaviours, thus it's easier to just write a bit of code to do what you want.

I am not convinced all suggestions above provide are a one for all solution. My scenario is I have a grouping that has has multiple columns. I could not use the agreed solution RunningValue because I don't have a single column to use in the function unless I combine (say a computed column) them all to make single unique column.
I could not use the VBA code function as is for the same reason and I had to use the same value across multiple columns and multiple properties for that matter unless I use some other kind of smarts where if I knew the number of uses (say N columns * M properties) then I could only update the RowNumber on every NxM calls however, I could not see any count columns function so if I added a column I would also need to increase my N constant. I also did not want to add a new column as also suggested to my grouping as I could not figure out how to hide it and I could not write a vba system where I could call function A that returns nothing but updates the value (i.e. called only once per group row) then call another function GetRowNumber which simply returns the rownumber variable because the colouring was done before the call so I always had one column out of sync to the rest.
My only other 2 solutions I could think of is put the combined column as mentioned earlier in the query itself or use DENSE_RANK and sort on all group columns, i.e.
DENSE_RANK() OVER (ORDER BY GroupCol1, GroupCol2, ...) AS RowNumber

Related

SSRS - how to create a double entry table

I need to create a report which is something similar to a Pivot Table.
The report would be something like below, with more towns
I C S Total
Town1 1 2 3 6
Town2 7 1 1 9
Town3 2 3 1 6
Total 10 6 5 21
In Crystal reports, there is an integrated function called Cross table
(see pictures below)
I'm looking for a similar function in SSRS, if there is any. I parsed the internet but I could not find anything that is relevant
Thanks!
You need a matrix to do so
Select the row, once the matrix created, like the image below and click on the row group and look at the group properties
You then choose the row for which you want to do the grouping like the image below
Repeat the operations for the column group.
You will need to add additional row and columns for the total.
I will do that for the row. You click the row to highlight it and then click on insert rows. You then choose Outside group below like in the picture below
Repeat the operations for the column group.
To have total, please put the following formula in your row and column created outside of the group SUM(COUNT(Fields!name_of_your_field.Value)) and you have the double entry table.
Let me know through the comments if you have any issues, I'll happy to help.

Merging multiple Rows in ssrs report to a single one

I need help regarding SSRS Reporting my data is Coming from a Query and I also have added the Column Group Named as Subject Name Showing on the top of the Table() Also Added ApplicantID as Row Group and FName as a Row Group in the Report to fulfill my requirement that was just to show
Since I am not Sure how many subjects a user can select its all decide on the run time so i did added the Subject name as a column group
All the Subject records in a single row for a specific ApplicantId Instead of showing below my Requirement is
It Should looks like as a table
Anatomy Surgery Zoology
Part ISt
14 Hanan Qureshi Iqbal Qureshi 15.00 20.00 10.00
15 Tasneem Alam Imtiaz Alam 30.00 10.00 20.00
etc instead of Showing in a seperate row it should show in a single row
Details group is your problem as #hemanth said you need to remove this and add in an aggregate function (max, min, sum, average) any will work since there is only one value for each SubjectName, Obtained Mark Combo. this will give you all the marks on one line for each applicant.

customizing the sort rows in a report

I'm trying to totally customize my report rows. Say I have a matrix report like this:
Category Smith Jones Johnson
Overhead 1,230.00 34.00 56.01
FTE (23.00) 105.00 2,389.00
RVU 3.00 787.00 89.00
Salary 44.00 782.00 9.00
Subsidy 11.00 4,561.00 389.00
TNS 4635.00 55.00 45.00
Is it possible to create a totally custom sort order? I would like to move RVU on top, then Salary, then TNS, etc. I found if I go into the Group Properties, I can define an expression like:
=iif(Fields!City.Value=”RVU”,”1″, iif(Fields!City.Value=”Salary”,”2″, iif(Fields!City.Value=”TNS”,”3″,”"...etc.
But that's very restrictive, and if I later want to move a row up or down, I have to go in and change all the numbers. What I'm looking for is a drag and drop approach that would let me change the order easily, and at any time.
Is this possible?
I would recommend adding a sort order to your dataset, it is the easiest to maintain, maybe a case sentence in your sql query,
Select Case when [Category]='RVU' then 1
when [Category]='Salary' then 2 end as Sortorder, [other], [columns]
then you can order by the sort order column
I can't think of an easy drag and drop solution to this problem

Using "totals" functions on an already grouped query

I am having troubles using the aggregate functions when using features like group by in a query. Instead of my aggregate functions applying to the entire query recordset, they only apply to select groups determined by the nature of the query. For example:
Person Date Able
-----------------------------
A 21/05/13 0
B 21/05/13 -1
C 21/05/13 -1
D 21/05/13 0
(grouped by Person, Date, Able)
When applying aggregate functions:
Person Date Able Max(Able) Min(Date)
----------------------------------------------------
A 21/05/13 0 0 21/05/13
B 22/05/13 -1 -1 22/05/13
C 23/05/13 -1 -1 23/05/13
D 24/05/13 0 0 24/05/13
The aggregate functions are made entirely redundant unless the data is completely ungrouped. So far, I have been getting around it using:
1) Using another query to reference the initial query and determine the true aggregate values.
2) Have the form call this second query using the d functions (dlookup,dcount etc.)
In my particular scenario, I have a list (very similar to above) that needs to be presented in a certain order (ranked based on ID). However, I am using an expression in the query to define a different type of ranking. The idea is to show (using conditional formatting) the first record in this new rank. Illustrated below
Person Date ID CalculatedRank
--------------------------------------------
A 21/05/13 1 4
B 21/05/13 2 2
C 21/05/13 3 3
D 21/05/13 4 1
Ideally I would like to have another column that determines which one is first which could be easily acheived by:
first: [CalculatedRank] = Min( [CalculatedRank] )
But as described above, Min() is not giving me 1, it is giving me it on a per row basis (the minimimum isn't always 1 so I can't set this arbitrarily).
Right now I am using a separate query to reference this first query and I sort that based on the calculated rank. Conditional formatting can then use dlookup to determine whether it is first or not from the second query. However, everytime the form refreshes, or a requery is called, every single row's conditional formatting triggers another dlookup, which then references the first query recalculating the new rank, for every row!
As you can imagine, the delay is noticeable causing the cursor to be idle for >5seconds. I am not too sure about the internal mechanisms of access, but using the inbuilt debugger, a requery on a recordset of 4 rows caused my CalculateRank() function to be called 12 times, purely through the conditional formatting calling the second query.
In summary, I have pretty much narrowed it down to requiring a separate query (and therefore dlookup) to properly use the aggregate functions. If I was able to keep everything in one query, the conditional formatting wouldn't need to use dlookup on another query to determine its status.
I am sure I am not the only one that has had problems with this and was wondering if any solutions exist where I can avoid all the stacked querying.
As always, any help is much appreciated!
Wow, I see what you mean! For my table [Table1]
Person Date ID
------ ---------- --
A 2013-05-21 1
B 2013-05-21 2
C 2013-05-21 3
D 2013-05-21 4
and my query [qryTable1Ranked]
SELECT Table1.*, CalculateRank([ID]) AS CalculatedRank
FROM Table1;
which uses the following function in a standard VBA Module
Public Function CalculateRank(ID As Long) As Long
Dim r As Long
Select Case ID
Case 1
r = 4
Case 4
r = 1
Case Else
r = ID
End Select
CalculateRank = r
Debug.Print "x"
End Function
and returns
Person Date ID CalculatedRank
------ ---------- -- --------------
A 2013-05-21 1 4
B 2013-05-21 2 2
C 2013-05-21 3 3
D 2013-05-21 4 1
when I just double-click the query to open it in Datasheet View my ranking function gets called 4 times, once for each row.
If I create a continuous form based on that query and open the form my function gets called 4 times. Then if I add conditional formatting on the [CalculatedRank] text box using Value = DMin("CalculatedRank", "qryTable1Ranked") then my function gets called 32 times!
I found that I can cut that by half (to 16 times) if I add an invisible unbound textbox named [txtMinCalculatedRank], use the following code behind the form...
Option Compare Database
Option Explicit
Private Sub Form_Load()
UpdateMinCalculatedRank
End Sub
Private Sub UpdateMinCalculatedRank()
Me.txtMinCalculatedRank.Value = DMin("CalculatedRank", "qryTable1Ranked")
End Sub
...and change the Conditional Formatting rule to Value = [txtMinCalculatedRank].
I found that I could cut that by half again (to 8 times) if I changed the Record Source of the Form from qryTable1Ranked to Table1 (the base table) and changed the Control Source of the [CalculatedRank] text box to =CalculateRank([ID]) (still using the tricks from the previous tweak).
I think that's probably as good as it gets without going so far as to create a temporary table, or persisting the CalculatedRank (and perhaps an "IsMin" flag) in the base table.

Reporting services put data from two DataSet rows in one tablix cell

I need to create report with table which looks like this
Country 1 Country 2 Country 3 Total
Category 1 1(2) 2(1) 5(6) 8(9)
Category 2 2(3) 2(1) 4(0) 8(4)
Category 3 3(2) 2(1) 3(1) 8(4)
Total 6(7) 6(3) 12(7) 24(17)
Report contains data about TFS WI's and has information about current week's WI count and last weeks WI count (in brackets)
Data set on which this report is based on MDX query against TFS warehousw cube and has such structure:
Category Country Week Count
1 1 this 1
1 2 this 2
1 3 this 5
1 1 last 2
1 2 last 1
1 3 last 6
Trouble is, I cann't find a way how to concatenate data about current and last weeks incident count in one cell. I have toyed around with idea to do it in MDX, but with my limited MDX skills I can't see how it could be done.
Rowgroup on Category.
Columngroup on Country.
Inside the cell you should be able to have 2 placeholders with the second one in brackets. The first expression should be:
=Sum(iif(Fields!Week.Value = "this", Fields!Count.Value, 0))
The second one should be:
=Sum(iif(Fields!Week.Value = "last", Fields!Count.Value, 0))
In MDX you could create two calcs - this and last week (of course you'll need to change this to work with your cube):
WITH
MEMBER [Measures].[thisWeekCount] AS
([Date].[Week].[this], [Measures].[Count])
MEMBER [Measures].[lastWeekCount] AS
([Date].[Week].[last], [Measures].[Count])
SELECT
{
[Measures].[thisWeekCount],
[Measures].[lastWeekCount]
} ON 0,
{
...
} ON 1
FROM [Your Cube]
Then, you can use them within placeholders as jimconstable explained, but without the iif functions.
Thank you all for your answers!
I found out that main problem (reporting services allows only one measure on columns) can be solved by using Analysis server OLE DB provider. There are some drawbacks, like that parameters are not supported, but I can live with this.