UNION multiple datasets in SSRS outside query - sql-server

I have two data sets with exactly the same fields that I would like to combine into one dataset.
I cannot put a UNION/JOIN and make it return one dataset in the query as all data is encrypted and gets decrypted by an assembly reference loaded in SSRS (so I cannot run the necessary WHERE's unless I use a filter once the data is in SSRS).
I can return the second dataset using Lookup/LookupSet however I am using this data in a bar chart so (somehow) need both sets of data to display on it. If I was using a tablix I would be able to "hack" it by putting a second tablix without headers underneath the main tablix and show it like that. Unfortunately being a graph I cannot do this.
I also tried running it as one dataset, returning all values and then running "filters" based on category groups in the chart however for whatever reason [bug in SSRS?] the filter on these filters the whole result set, not just the one category group.
Is what I am trying to do possible in SSRS? Seems so basic but after a week of trying I have just about given up!

Merging two datasets is not possible but there may be a way to fake it for your chart purposes by doing a SUM of LookUpSet. What ever field is used as your value needs to be looked up using whatever criteria is being used for your axis.
Let's say you're displaying sales by month. Your value field is SUM(Fields!TotalSales.value) and your date field is Fields!month.value. You'd want to add the value from dataset1 and lookup the total from dataset2 - like:
=Fields!TotalSales.value + Code.SumLookup( LookupSet(Fields!month.Value, Fields!month.Value, Fields!TotalSales.value, "Dataset2") )
Unfortunately, SSRS doesn't let you sum a lookupset (so what's the point of it?), so you have to use custom code to do it.
Function SumLookup(ByVal items As Object()) As Decimal
If items Is Nothing Then
Return Nothing
End If
Dim suma As Decimal = New Decimal()
suma = 0
For Each item As Object In items
suma += Convert.ToDecimal(item)
Next
Return suma
End Function
Stolen from: How to combine aggregates within a group with aggregates across groups within SSRS
You're data is obviously different but the concept should be the same.

Related

Way to calculate difference between Tab Filter and Overall in Google Data Studio?

I have a calculated value in Google Data Studio that a client wants to see as follows:
Result = Value (No filters on page applied) - Value (Filters on page applied dynamically)
I don't know how to calculate or accomplish this in Google Data Studio or if this is possible. Can someone show me if this solution is possible?
There are two workarounds:
Parameters
Instead of using filters, create a parameter1 and a field with the function
Value -
case when parameter1=some_field then Value
else 0 end
Blend
Duplicate the data source and hide all field which shall not be filtered. Blend this data source with the original one and use as joining keys the dimension which are not filtered. Use the field Value in both sets as metrics and rename it as filtered / not filtered.
Add a chart and add in this chart a metric field with a formula substracting these two Value fields.

How do I achieve this output in a Google Data Studio report, given the raw data?

I have a small set of test records in Google Data Studio and am attempting to create a table that gives me breakdowns of particular values relative to the total number of values, by dimension. I think the image here below describes the need clearly. I have tried using an approach I saw online entailing creating a calculated field like this:
case when Action = 'Clicked' then 1 else 0 end
and then creating a metric based upon that field, which does the 'Percentage of Total - Relative to Corresponding Data' but this produces incorrect numbers and seems really cumbersome (needing one calculated field per distinct value). My client wants this exact tabular presentation, not a chart(s).
How do I achieve the desired report?
Thanks!
Solution entails creating fields like 'Opened' which outputs 1 when Action = 'Opened', 0 otherwise. Then create fields like 'Opened Rate' with e.g. sum(Opened) / Record Count. Then set those as percentages.

Report Builder 3.0 Add Data Elements to an Array

I'm currently working on building a dashboard for some hospital metrics. The state requires that we report median key times. This dashboard will need to display the group median time for each day and the total column will need to display the entire dataset's median.
I'm working with Report Builder 3.0 and SQL Server 2014.
I've built a stored procedure that can calculate all these values accurately but accomplishing the mean this way makes expanding the dataset a bit of a monster when a new field needs to be pulled in.
All the articles (like as this one) I've read for calculating median within Report Builder point to needing to display (or insert and hide) all the data from the dataset. This method seems really hacky to me and is going to make this dashboard an absolute monster to try to manage as it grows.
What I need to know is, is there any way to pass the group values to a custom code function? The report has to have access to the group values at some point or else it wouldn't be able to perform the built in aggregate functions (Sum, First, Last, etc) on these groups. If I can't pass these values as an array to a custom code function, does anybody know how the group aggregate functions are built?
Thanks in advance to any who might have a direction to point me.
You can pass the values from the procedure to a function within SSRS and then have it just display the resulting median. I'll just give you summary to get you started.
Create a hidden parameter that allows multiple values.
Set its available values to pull from the dataset that is populated by your stored procedure.
Also set its default value so that all values are selected by default.
Go to the Code section of the report properties to write your function.
The function will take the parameter as an argument like this Public Function MyFunc(ByVal p1 as object()) as Integer
In the function you can refer to p1.Length and an item in the array like so: p1(i)
In the report you can call the function in an expression like this: =Code.MyFunc(Parameters!p1.Value)
Hope this points you in the right direction.

Vlookup data greater than 0 only from two columns

On my first tab, I need to return the data from the second tab, columns A,B and C; only when the value of column A is greater than 0. I have pics to send but don't see a way to upload them. Currently using this formula, but have been unable to expand on it to get what I need.
=VLOOKUP('MSA Units'!A4, 'MSA Units'!A4:C882,1,FALSE)
I have also tried various forms of INDEX and MATCH arguments with no good results.
HERE IS REVISED LINK TO IMAGES: http://imgur.com/a/20J0v
Filter MSA Units and for columnA select all other than (Blanks). Copy ColumnsA:C of what remains visible into Daily Report Coversheet.

SSRS Chart: Filtering and controlling axis maximum

I am creating a chart off in SSRS based on software version usage per month. I would like to compare how often each version is used per month in comparison to other versions. The image I'm working with is below:
Obviously with one version being used so highly, it visually skews my data, making the rest of the data harder to see. I am curious if there is any way to do the following things in SSRS:
Having the user Toggle /select/choose which versions they would like to appear on the chart, with the chart then automatically adjusting its Y-Axis settings
Having the user adjust the y-axis settings themselves, thus being able to get a closer look or a zoomed out look of the data.
There are a few questions here.
Here's my base report:
Parameter-based axis
You can definitely set axis limits with a parameter. I created a parameter called AxisLimit and set Maximum property to use this parameter under Axis Options -> Set axis scale and style:
Works as required:
Filtering by parameter
You can also set up the report to filter values based on a user selection.
You can apply this to the DataSet in the query text or as a parameter to an underlying stored procedure.
If you need the data elsewhere in the report and can't apply this at the DataSet level, you can set up a filter at the chart level. I set up a multi-value parameter called Groups which contains the groups in the DataSet.
At the report I set the filter as:
Where the expression is:
=IIf(InStr(Join(Parameters!Groups.Value, ",")
, CStr(Fields!grp.Value)) > 0
, "INCLUDE", "EXCLUDE")
Here I use the Join function to get the list of selected parameters values, then filter the DataSet based on these. Again, works as required:
Scale breaks
One option you might not have considered is Scale Breaks, which is meant to help with this sort of data:
Maybe this will help, too.

Resources