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

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.

Related

Aggregate values and display in chart

I am struggling with this problem and I can't figure out how to solve it.
This is my dataset detail data:
Order Item StartDay EndDay EndYear StartEndDiff
1 1 01.01.2018 02.01.2018 2018 1
1 2 03.01.2018 05.01.2018 2018 2
2 1 05.01.2019 06.01.2019 2019 1
2 2 06.01.2019 06.01.2019 2019 0
2 3 08.01.2019 10.01.2019 2019 1
3 1 07.01.2019 08.01.2019 2019 1
I now group them by Order (this works fine in a tablix). Group name is OrderGroup:
Order MinStartDay MaxEndDay EndYear MinStartMaxEndDiff
1 01.01.2018 05.01.2018 2018 4
2 05.01.2019 10.01.2019 2019 5
3 07.01.2019 08.01.2019 2019 1
For MinStartMaxEndDiff I got the following expression:
=DateDiff("d", Min(Fields!StartDay.Value, "OrderGroup"), Max(Fields!EndDay.Value, "OrderGroup"))
Now I added another group in the tablix and displayed the Avg(MinStartMaxEndDiff) per EndYear. This still works fine in the tablix with all the groupings. The result:
Avg(MinStartMaxEnd) Year
4 2018
3 2019
But I can't figure out how to display only the data from the result, based on the calculations, in a chart. I normally do these calculations on the SQL side, but this time I can't do them SQL side.
The problem is when I try to add the OrderGroup in the chart it always shows me the details. But I need this group to get the right values. Hide or set the category label to Nothing didn't work. Also setting the DataElementOutputto NoOutput didn't help (real look):
I would just need on the x-axis the Years and as values the Avg(MinStartMaxEnd). This would be my desired output based on the sample data from above:
EDIT AFTER A SOLUTION WAS FOUND:
What can I do if a row data looks like this:
Order Item StartDay EndDay EndYear StartEndDiff
1 1 29.12.2018 02.01.2019 2019 4
1 2 28.12.2018 30.12.2018 2018 2
This one will get divided into two separate datarows in the tablix, because of the EndYear grouping. The expected result should be look like this:
Order MinStartDay MaxEndDay EndYear MinStartMaxEndDiff
1 28.12.2018 02.01.2019 2019 5
But a grouping of the year with the expression
=Max(CDate(Fields!EndYear.Value), "OrderGroup")
is not possible.
You can use custom code inside your tablix to calculate the average per year, and call the calculated values in the chart.
Add the following custom code to your report
Public Dim YearAvg As New System.Collections.Generic.Dictionary(Of String , Decimal )
Public Function SetYearAverage( ByVal s As String, ByVal d AS Decimal) As Decimal
YearAvg.Add(s,d)
Return d
End Function
In the textbox you calculate the year average change the expression to the following (make the appropriate changes to field names)
= Code.SetYearAverage(Cstr(Fields!EndYear.Value), Avg ( DateDiff("d", Min(Fields!StartDay.Value,"OrderId"), Max(Fields!EndDay.Value,"OrderId"))))
Then set your chart expression to
= Code.YearAvg( Cstr( Fields!EndYear.Value))
This is not an answer as I didn't get the results you were expecting, work got in the way! However, it's fairly close so I thought I would post it in case it was any help.
A pity doing this on the server was not an option as it would be really easy.
Anyway, I replicated your dataset (with a couple of field name changes to avoid keyword conflicts) and set the chart up as follows..
Category groups - None
Series Groups 2. Parent group is on 'EndYear' called 'ChartYearGroup', child group is on OrderID called 'ChartOrderGroup'
Values - Here I set the Category Field to [EndYear] and the expression was
=AVG(DateDiff(
"d"
, Min(Fields!StartDay.Value, "ChartOrderGroup")
, Max(Fields!EndDay.Value, "ChartOrderGroup")
)
, "ChartYearGroup"
)
This does give the correct numbers but unfortunately shows per order rather than per year.
I'm not sure if this will be possible to resolve. Somehow I guess you'll have to hide the order group or combine the two groups into one, I just ran out of time to test.
Here's the end result.

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.

SQL Report Builder for Survey Data

I have a large dataset with People's names and their Rating from 1 to 5.
Then I made a query that summarizes this data for PersonA:
Rating Count
------- ------
1 4
2 6
3 1
4 0
5 2
I just need to know how to show this on my report.
I have made a cell for each rating and need to put in an expression that says "If Rating=1, show count for rating 1".
I tried using =IIf(Fields!Rating.Value = 1, Fields!Count.Value, 0) but this didn't work.
I'm not sure why you would need an expression like that, based on your description of the dataset it sounds like you already have two columns of data for rating and count, so you could use a tablix (table), with columns:
Rating Count
which would list all the rating values and associated count values, similar to the example result in your question.

RowNumber for group in SSRS 2005

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

How to do SUM(VacancyID) without Duplicates while also showing Count(VacancyStartID) in the same Group?

In SSRS 2005 I am reporting on all available posts by regional office, listed by region,office,vacancyID.
I then display a total per office on how many people started in a particular vacancyID by doing a Count(VacancyStartID).
In the same group row with the Count(VacancyStartID) I need to display SUM(VacancyID).
However at present this does not give the correct SUM, because some vacancies have multiple VacancyStartID's and hence the vacancyID is listed few times, like so:
office vacancyID Number_of_vacancies VacancyStartID (person who started a job)
1 1 2 4567
1 1 2 5678
Totals: 4 (needs to be 2) 2
P.S. Note:These questions are not applicable in this instance:
How can I remove duplicate rows?
How do I remove "duplicate" rows from a view?
Using multiple COUNTs and SUMs in a single SQL statement
If it's in the Underlying SQL Server call...
You can do ...SUM(DISTINCT VacancyID)... like you can COUNT (DISTINCT ..)
Edit:
SELECT
col1, col2, SUM(DISTINCT Number_of_vacancies) as foo, COUNT (VacancyStartID) as bar
FROM
MyView
...
If it's in the table or for a cell in the report, then there is no equivalent in the SSRS SUM function.
Do some grouping already in your query and then make a group with a simple Count in SSRS.