SSRS Grouping Data Together - reporting-services

I have a report that lists securities that are held and there security types. I want to some business logic that says security types 1, 2 and 3 are Equities, while security types 4, 5 and 6 are Bonds and then I want to group the report by these. Any idea how to do that? Right now the report lists each individual security type.

amend your dataset: within your select sql statement , lastly add the following:
CASE WHEN [security types] IN ('1', '2', '3') THEN 'Equities'
WHEN [security types] IN ('4', '5', '6') THEN 'Bonds'
ELSE 'others'
END AS securitiestype
Then with in your SSRS report you can now use securitiestype as a group filter.

A good way to do this is to add a calculated field to your dataset that evaluates this logic. Then you can group on this new column in the report.
Go to your dataset properties
Add a calculated field
Name it and enter the expression for it. It could be something like this:
=Switch(Fields!SecurityType.Value = 1 OR Fields!SecurityType.Value = 2 OR Fields!SecurityType.Value = 3, 'Equity'
,Fields!SecurityType.Value = 4 OR Fields!SecurityType.Value = 5 OR Fields!SecurityType.Value = 6, 'Bond', true, 'Other')
Add a grouping to your table/matrix using this new column

Related

Changing field fill of max value in column groups on SSRS 2014

I have a table in SSRS that has both row and column groups.
For each row group [Cat], I need to highlight the highest value in the column group, which is the sum of all counts for that category in a given month.
Can't for the life of me figure it out, so if anyone could help that would be great!
Thanks
Example of dataset
This is what I'm aiming for
Table in Design View
Current outcome
The problem you will face is that you will have to try to use nested aggregates with scopes defined. This might be possible (but I don't think it is...)
There is a fairly simple way to fix it though. I can;t give an exact answer as I don;t know what your dataset looks like but typically you would have to make some changes to your dataset, then its simple.
So assuming your dataset looks something like this
Cat myDate counts
A 20171001 90
A 20171001 6
B 20171001 18
C 20171001 1
A 20171101 100
A 20171101 20
....
....
Then aggregate everything so the report does not have to do any real aggregation with something like
SELECT
*
, max(counts) OVER(PARTITION BY Cat) as maxInCat
FROM (
SELECT
Cat, myDate
, SUM(counts) as counts
FROM myTable
GROUP BY Cat, myDate
) x
This will give you a dataset with an additional column maxInCat. This column will contain the maximum value in each category so we can compare against this in the report.
The expression can then be something like
=IIF(SUM(Fields!counts.Value)>0 and SUM(Fields!counts.Value) = Fields!maxInCat.Value, "Yellow", Nothing)
EDIT
I've updated the actual backcolor expression as it didn't account for blanks/zeros
Ignoring the fact the the columns are not sorted as I don't have time, here's the result
Here's an answer that I think does what you need:
declare #Table as table
(
[Cat] char(1),
[Sector] tinyint,
[Counts] int,
[Date] date
);
insert into #Table
(
[Cat],
[Sector],
[Counts],
[Date]
)
values
('A', 1, 4103, '2017-10-01'),
('A', 1, 3001, '2017-11-01'),
('A', 1, 1128, '2017-12-01'),
('A', 1, 5917, '2018-01-01'),
('A', 1, 9594, '2018-02-01'),
...
So you know where the data is coming from.
with [AggregatedData] as
(
select
t.Cat,
t.Sector,
t.Counts,
t.[Date],
sum(t.Counts) over (partition by t.Cat, t.[Date]) as [SumCounts]
from #Table as [t]
)
select
ad.Cat,
ad.Sector,
ad.Counts,
ad.[Date],
ad.SumCounts,
max(ad.SumCounts) over (partition by ad.[Date]) as [MaxSumCounts]
from [AggregatedData] as [ad]
Then in SSRS, you can use:
=iif(IsNothing(Fields!SumCounts.Value) = FALSE AndAlso Fields!SumCounts.Value = Fields!MaxSumCounts.Value, "Yellow", "Transparent")
Which gives:

How to not COUNT a value in SSRS matrix when value is NULL

I cannot make the my expression NOT count a NULL value in my SSRS matrix.
In my SSRS matrix, I have 2 columns one for AppraisalCompany and a count under the SubmittedDate column. In my report this what is happening:
Per Derrick's suggestion here is the change I made in the ColumnGroup properties for the SubmittedDate:
Here is my expression change in the ColumnGroup properties:
Unfortunately I got this error:
I'm suspicious of your Dataset, I'm not entirely sure how you're getting a null value to return 1 in the COUNT. I have been unable to reproduce your results.
Dataset Query
SELECT 'Drive In' AS AppraisalCompany, NULL AS SubmittedDate
UNION
SELECT 'Photo App - English', 'Dec-18'
Next I created a Row Group on AppraisalCompany and a Column Group on SubmittedDate.
I filtered the column group to remove the null grouping, using the expression =IsNothing(Fields!SubmittedDate.Value), operator <>, and Value true.
In the textbox in the matrix I used [Count(SubmittedDate)].
OUTUT
Appraisal Company | Dec-18
-------------------------------
Drive In | 0
Photo App - English | 1
By a Decimal (Number) datatype Nothing and 0 are the same. You can test this.
Put a tablix into your report with year from 2017 to 2019. Then put the year in a column of the tablix as a number format, then write the following expression in the detail textbox:
=CDec(IIF(CDec(Fields!Year.Value) = 2017, 0, Nothing))
After executing your report you will notice that every value in the year column is 0.
The same goes for the check. Both of these expressions will always return Yes. I basically check for 0 and the second one for for Nothing:
=IIF(CDec(IIF(CDec(Fields!Jahr.Value) = 2017, 0, Nothing)) = 0, "Yes", "No")
=IIF(CDec(IIF(CDec(Fields!Jahr.Value) = 2017, 0, Nothing)) = Nothing, "Yes", "No")
But remember your textbox/column has the be a number format.
So if you want to return Nothing and you display it in a number format textbox, it will show you a 0.
With this in mind it will make sense that a Count() returns the value 1 for 0 AND Nothing. So basically this will do the trick:
'Cont
=Sum(IIF(Fields!YourValue.Value = Nothing, 0, 1))

how to get sum(group) value in rdlc

I am developing report in RDLC (VS 2012)
below is my report
In this report i have two group total value matrix table.
I want to minus Sum(income) and sum(expenses).
Total should be show as 2121.00
how its possible ?
Try using:
=SUM(IIF(Fields!VoucherType.Value = "Income",Fields!Amount.Value,0))-
SUM(IIF(Fields!VoucherType.Value = "Expenses",Fields!Amount.Value,0))
Update
Textbox outside of the tablix.
If you want to show the total outside of the tablix you need to set the scope of the expression, in this case the dataset:
=SUM(IIF(Fields!VoucherType.Value = "Income",Fields!Amount.Value,0),"DataSetName")-
SUM(IIF(Fields!VoucherType.Value = "Expenses",Fields!Amount.Value,0),"DataSetName")
Replace DataSetName by the actual name of your dataset.
=SUM(IIF(Fields!TransactionType.Value = 1), Fields!Amount.Value, 0) -
SUM(IIF(Fields!TransactionType.Value = 2), Fields!Amount.Value, 0)

SSRS Multiple Field Values Not Passing As Parameters To Drilldown Report

I have not found a suitable answer to my following problem after much searching.
I have a summary report which shows the total number of appointments by month grouped by specialty name and diagnosis.
Specialty_Name Diagnosis Code Feb Mar Apr
Neurology G35X 0 3 4
G379 8 5 7
Total For Spec 8 8 11
Rheumatology H051 4 9 2
M059 6 10 3
Total For Spec 10 19 5
When I click on the field (ie 11 for Neurology Total For Spec, Apr), which is =COUNT((Fields!Appointment_ID.Value), I want to pass each of the Appointment_IDs to a sub query as the parameter to display the associated client details. However, when I prepare the sub query and drill down report in a manner that I have used before I am only getting the result of the first Appointment_ID; not each one.
The sub query report is set up with the parameter #Appointment_ID VARCHAR(MAX) and a WHERE clause:
CAST(App.App_ID AS VARCHAR(MAX)) in (
SELECT * FROM Serve1.dbo.CreateParameterTable(#Appointment_ID,',')
)
The CreateParameterTable is a function on our server which should handle the string from the summary report and does so on other reports.
(
#StringInput NVARCHAR(MAX)
, #SplitBy NCHAR(1)
)
RETURNS #OutputTable TABLE ( [String] NVARCHAR(36) )
AS
BEGIN
DECLARE #String NVARCHAR(36)
WHILE LEN(#StringInput) > 0
BEGIN
SET #String = LEFT(#StringInput,
ISNULL(NULLIF(CHARINDEX(#SplitBy, #StringInput) - 1,
-1), LEN(#StringInput)))
SET #StringInput = SUBSTRING(#StringInput,
ISNULL(NULLIF(CHARINDEX(#SplitBy, #StringInput),
0), LEN(#StringInput))
+ 1, LEN(#StringInput))
INSERT INTO #OutputTable ( [String] )
VALUES ( #String )
END
If I manually type in multiple Appointment_IDs to my drill down report I get the expected result. Therefore it appears that either my Summary Report is not passing out a string or it is not being handled correctly by the function or the sub report does not like the output of the function Which as I have said works on other reports we have written. I'm stumped.
How to begin troubleshooting your specific problem
Because you've said you can get the subreport working by supplying a string of values as desired, then it appears the problem is with the report providing the delimited string. Before you can fix the issue, you need to see the delimited string being passed to the subreport - so add it to the tablix. Use the same function you're using to reference the value in the "Go to Report" action and add it as a tooltip to each count. That way you can see the string being prepared and tweak your logic until it comes out correctly.
How I would solve your problem
What you're trying to accomplish as a multi-valued parameter is, as I see it, unnecessarily complicated.
In your tablix, you have a set way of organizing the results. You have specialty name, diagnosis, and month (presumably of the diagnosis or date served).
That's three parameters you can pass through to a sub-report. Using similar sql logic as exists in your main report, you can isolate those 11 simply by knowing the values of those three fields plus the year. Obviously, you will need to do some work to find diagnosis/service dates that fall into a given month, but that's not too hard:
Where Month(Date_of_Service) = #Month
and Year(Date_of_Service) = #Year
and Specialty_Name = #Specialty
and Diagnosis_Code = #Diagnosis

Rails join two tables or replace numbers by the words

I want to write logs to the database and I have often repeated words (syslog, sms, voice, email), I need to instead these words insert numbers (syslog - 1, sms - 2, voice - 3, email - 4), so as not to clog the base repeating words. And then select the words instead numbers
Excuse me, i asked the question wrong. I have data already saved, and i need select it to my index.html.erb. query must be like this: "SELECT triggerid, severity, status, types.name FROM logs, types WHERE logs.type_id = types.id;" logs.type_id = (1, 2, 3, 3, 2, 2, 1), types.name = (email, sms, syslog, voice), types.id = (1, 2, 3, 4,) after query myst be: types.name = (email, sms, syslog, syslog, sms, sms, email). How can i use activerecord fo this result?
I'm not sure what field name/table your wanting to store these numbers in so I'm going to just call it 'FIELD_NAME' and 'TABLE'. Keeping it in mysql you could do this:
Retrieve:
SELECT TABLE.*, case FIELD_NAME WHEN 'syslog' THEN 1 WHEN 'sms' THEN 2 WHEN 'voice' THEN 3 WHEN 'email' THEN 4 ELSE null END as FIELD_ALIAS FROM TABLE
the result will have an attribute of FIELD_NAME with the int value, and an attribute of FIELD_ALIAS with the text version.
Inserting (STR_VALUE is the string version of the field):
INSERT INTO TABLE_NAME (FIELD_NAME) VALUES (case STR_VALUE WHEN 'syslog' THEN 1 WHEN 'sms' THEN 2 WHEN 'voice' THEN 3 WHEN 'email' THEN 4 ELSE null END)
I believe a better alternative though would be to offload this to your model. for simplicity I'm going to refer to your integer version as 'int_value'.
class Address < ActiveRecord::Base
before_save :convert_int_value
def str_value
case self.int_value
WHEN 1 THEN 'syslog'
WHEN 2 THEN 'sms'
WHEN 3 THEN 'voice'
WHEN 4 THEN 'email'
end
protected
def convert_int_value
return nil unless int_value.is_a?(String)
self.int_value = case self.int_value
WHEN 'syslog' THEN 1
WHEN 'sms' THEN 2
WHEN 'voice' THEN 3
WHEN 'email' THEN 4
end
end
Anytime you want the int version, just call int_value on your model. If you want the string call str_value. Additionally you can store the string version, in your int_value and before the record is saved it will convert it for you. This way all you have to pass mysql is an integer.
Update per comment
If your associations are set up correctly (Log belongs_to :type)
Log.includes(:type).each do |l|
l.status
l.type.name #> email, sms, or syslog
end
I realized after the fact there is another solution as well, I think this is more what you were looking for
Log.joins(:type).select('triggerid, severity, status, types.name')
Alt1
Log.joins(:type).select('log.*, types.name')
Alt2
Log.joins('JOINS types ON types.id = logs.type_id').select('log.*, types.name')
are you after one address per client?:
Client.joins(:addresses)
or every address with client info?:
Adress.join(:client)