SSRS 2012 MATRIX TOTAL DYNAMIC COLUMNS BY COLUMN HEADING - reporting-services

Simple Q:
In SSRS 2012: require a matrix with column totals derived from the dynamic column headings;
e.g.
Period 1 2 3 Total Total
Type Act Bud Act Bud Act Bud Act Bud
Total 10 9 10 9 10 9 30 27
is this possible in SSRS?
Can easily get the total of the sum of columns -(57) but not split by type.
Thank You.
data is grouped ;
Business Unit - Row Group
Account Type - Row Group
Month Period - Column Group
Amount_Type (Act, Bud) - Column Group
The Aggregate is Amount
Tks

Without knowing the structure of your dataset I think you can add two columns outside the columns groups at the right side and use these expression to calculate the respective total:
For Actual total:
=SUM(IIF(Fields!Type.Value = "Act",Fields!Amount.Value,0))
For Budget total:
=SUM(IIF(Fields!Type.Value = "Bud",Fields!Amount.Value,0))
UPDATE: Try setting the scope of the SUM function.
=SUM(IIF(Fields!Type.Value = "Act",Fields!Amount.Value,0),"DataSetName")
Replace DataSetName by the actual name of your dataset.
Let me know if this helps.

Related

SSRS - Percentage Totals Row

I am trying to build an SSRS report that has a column based on a percentage:
AgentSales AgentCommission Commission
20 .25 5
33 .12 3.96
46 .76 34.96
Totals: 99 [Unknown Calculation]
However, where I am having problems is I need to get what would be the totals column? How would I calculate the Commission so that the number shown in [Unknown Calculation] to display what I assume would be the average commission?
Commission column is simply AgentSales * AgentCommission. The total commission wouldn't be a SUM(Commission), but would more or less be the average commission for all agents.
Assuming you want to calculate the weighted average commission then I would calculate it like this..
Expression 1: is simple as per your sample.
=Fields!AgentSales.Value * Fields!AgentCommission.Value
Expression 2: is the sum of the results of expression 1
=SUM(Fields!AgentSales.Value * Fields!AgentCommission.Value)
Expression 3: is the expression 2 divided by the sum of agent sales
=(SUM(Fields!AgentSales.Value * Fields!AgentCommission.Value))
/
SUM(Fields!AgentSales.Value)
The other cells should be self explanatory...
When we run the report we get the following.
If this is not what you wanted, then please edit your question to show the desired result and how you arrived at that result.
EDIT AFTER UPDATE FROM OP
If you want the cell marked "2" in my sample to be an average of the values above then simpley change it to
=AVG(Fields!AgentSales.Value * Fields!AgentCommission.Value)

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.

FileMaker - Total SubSummary Values

I have a table with records each representing an appointment. I have the name of the contactthe appointment is with, and the date. In another table I have a field that contains how many appointments each contact is supposed to have during the day. There are 12 entries for each contact, because some are expected to have different numbers during different months.
I am able to call up the data for the appropriate contactfor the appropriate month. It looks great in the graph when I count up the number of entries for Contact A and put next to it the expected number of entries from the related table.
The problem I'm running into now is that I need to add up all of the expected appointments between all of the entities. So:
::ContactName:: ::appointments:: ::expected::
Contact A 12 10
Contact B 33 34
Contact C 18 27
Getting the roll up for the actual appointments is easy, a simple COUNT summary field in a subsubsummary section. But what of the expected? Because ContactA had 12 appointments that means that there will be 12 records for them, so putting a summary field for the expected column is would return 120 for all Contact A's. Instead, given the dataset above, I need the calculation to return 71. Does this issue make sense? Any help would be greatly appreciated.
If I am following this correctly, you need to divide the amount of expected appointments between the entries of the group, then total the result. So something like:
Sum ( Entities::Expected ) / GetSummary ( sCount ; EntityID )
(this would be easier if we knew the names of your tables and fields).
P.S. The term "entity" has a specific meaning in the context of a relational database. Consider using another term (e.g. "contacts").
Added:
Using your example data, you should see the following results in the above calculation field:
in the 1st group of 12 records: 10 / 12 = .8333333333333333
in the 2nd group of 33 records: 34 / 33 = 1.0303030303030303
in the 3rd group of 18 records: 27 / 18 = 1.5
When you sum all this up (using a summary field defined as Total of this calculation field), you should get 71 (or a number very near 71, due to rounding errors).
Note: in the above calculation, sCount is a summary field defined in the Appointments table as Count of [ any field that cannot be empty ], and EntityID is the field by which your records are sorted and grouped (and it must be a local field).

Compare 2 dynamically created matrix columns to get a difference

I have a matrix set up with a Row Group called "company", a Column Group called "Year" and a value field that is a sum of charges through the year called revenue. The column Group will end up having 2 columns in it that are provided through user input. The end results is a matrix that will look something like this:
Year 1 | Year 2
Company: $500 $250
Company2: $750 $250
What I would like to do is add a column to the matrix that calculates the change from year 1 to year 2. Is there a way to do this within the matrix such as adding a new column with an expression that compares the 2 entries in the row or will I need to manipulate the SQL code to create a column that does this within the code? To that end here is a view of the code for the dataset if that is the way I need to go:
SELECT
company.cmp_id
,company.Company
,ChargeDetails.[Bill To ID]
,ChargeDetails.[Delivery Year]
,ChargeDetails.Revenue
FROM
ChargeDetails
LEFT OUTER JOIN company
ON ChargeDetails.[Bill To ID] = company.cmp_id
WHERE
ChargeDetails.[Delivery Year] = #DeliveryYear
OR
ChargeDetails.[Delivery Year] = #ComparisonYear2
ORDER BY ChargeDetails.[Delivery Year] DESC,ChargeDetails.Revenue DESC;`
Try to add a column outside the Year group in header type Change or what you want to put, in the below cell use this expression:
=Sum(iif(Max(Fields!DeliveryYear.Value)=Fields!DeliveryYear.Value,Fields!Revenue.Value,0))-
Sum(iif(Min(Fields!DeliveryYear.Value)=Fields!DeliveryYear.Value,Fields!Revenue.Value,0))
Note I am substracting the min year (1) revenue sum to the max
year (2) revenue sum.
In your example it will produce:
+-----------+--------+--------+--------+
| Company | Year 1 | Year 2 | Change |
+-----------+--------+--------+--------+
| Company A | 500 | 250 | -250 |
+-----------+--------+--------+--------+
You can define change in many ways maybe in percentage or any other measure, this is only an example, learn what the above expression is doing in order to calculate the measure you need.
EDIT 1:
Add the matrix with this data arrangement.
The matrix looks like this one in preview:
Be sure you added the Change column outside the DeliveryYear group as shown in above image. Also check the fields names correspond to yours in the expression.
EDIT 2:
If Revenue has null values you can try this:
Try replace the null values at query level using T-SQL ISNULL() Function, change your query in this part as follows
,ISNULL(ChargeDetails.Revenue,0)
However if DeliveryYear has null values you may want to ignore that records, so try to exclude it in the where clause.
Let me know if you need further help.
I ended up using the following as the expression in the change column.
=sum(iif(Fields!Delivery_Year.Value=Parameters!DeliveryYear.Value,1,0)*Fields!Revenue.Value) - sum(iif(Fields!Delivery_Year.Value=Parameters!ComparisonYear2.Value,1,0)* Fields!Revenue.Value)

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.