Aggregate values and display in chart - reporting-services

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.

Related

SSRS Grouping merge details

Here is my table
EmployeeNr IDNumber Period MonthlyIncome IncentiveAmount
0000002 8912135105086 2017-04-30 3975.00 1000.00
0000002 8912135105086 2017-05-31 4658.38 670.31
0000002 8912135105086 2017-06-30 5292.19 353.90
0000003 4912015215108 2017-05-31 4274.38 862.81
0000003 4912015215108 2017-06-30 5503.75 248.13
Here is how i am able to display it with grouping:
So my question is can i display it with grouping so that the different values for each employee is only in one row?
I know how to get to the result with creating a table on my query select with all the months and looping trough to ad the values but I would like to avoid that if possible
EDIT
Here is how i want it to display:
The test come from
=IIf(Month(Fields!Period.Value) = ((Month(First(Fields!StartDate.Value,
"PayrollTaxYear")) + 0 - 1) Mod 12) + 1, Fields!MonthlyIncome.Value, "test")
I use this statement to display the data under the month it is in according to the payroll year start and end, That is also why it start on this example from march.
Edit 2
First One
Second One
You just need to use column grouping in your report, which has the same effect of using a pivot:
The expression for the month name headings is just =MonthName(Month(Fields!Period.Value))
Which outputs:

SSRS 2012 MATRIX TOTAL DYNAMIC COLUMNS BY COLUMN HEADING

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.

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)

Variable Month mmm and Append to static text Field in SQL select Reporting design Studio 2005

I have a Budget table with field names "SSBJAN", "SSBFEB", "SSMAR", etc for the year
My select query which works ok below, I currently change manually "SSBMAY" each month:
SELECT SADIVO AS Division, SAWHSL AS Location, SSBMAY as BudgetSales,
FROM BBSCDTA.SA04WH
I wish this to pickup from Month(Today()) with the current Month 'mmm' so I can append it to SSB so it auto selects current month from table.
Below I have created this in QlikView coding but am not able to get this working in Report Designer SQL.
My code for Qlikview
Let Today='03/05/2012';
let CalBud1=Upper(Month(Today()));
let SSB=Upper('SSB');
let vCalBud=SSB&CalBud1;
This returns "SSBMAY" and next month it returns "SSBJUN"
Assuming that you want the query for T-SQL (Microsoft's dialect of SQL)
SELECT
SADIVO AS Division,
SAWHSL AS Location,
CASE MONTH(GETDATE())
WHEN 1 THEN SSBJAN
WHEN 2 THEN SSBFEB
WHEN 3 THEN SSBMAR
WHEN 4 THEN SSBAPR
WHEN 5 THEN SSBMAY
WHEN 6 THEN SSBJUN
WHEN 7 THEN SSBJUL
WHEN 8 THEN SSBAUG
WHEN 9 THEN SSBSEP
WHEN 10 THEN SSBOCT
WHEN 11 THEN SSBNOV
WHEN 12 THEN SSBDEC
END as BudgetSales
FROM BBSCDTA.SA04WH

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.