How can I get SSRS to create subheadings? - sql-server

The Problem
I'm building an SSRS report which requires regular group headings on certain rows. The data returned from the database query includes a column with a bit flag indicating which rows need to be treated as group subheadings.
Here's a snippet of the source data:
Note the IsGroupHeading column, where the flag is set to 1 on the first row ("0401").
I want to produce output which looks like this Excel mockup:
So every time the report encounters a row where IsGroupHeading equals 1, it generates a bold group heading row followed by a row with column headings.
What's Happening
I've tried creating a row group in SSRS with the expression =Fields!IsGroupHeading.Value = 1 but I get unexpected results: (1) Only the first group heading is treated specially, and (2) the group heading row is repeated underneath the heading. The result looks like this:
Notice that the "0401" row is repeated under the group heading. In addition, only the first group heading ever gets this special treatment. The report simply ignores subsequent group headings and renders them as normal data rows.
The Question
I've spent hours trying to get this right and this is the closest I've been able to get it and my googling on row groups turns up pages mostly about creating subtotals, so I'm throwing this one out to the community hoping some SSRS experts can help me with this.

I'm going to assume that you're doing this in SQL and that all tariff numbers start with the group header tariff number (in this case, 0401).
Let's say your SQL currently looks like this:
SELECT TariffNumber, RowDescription, TariffRate, IsGroupHeading
FROM Tariffs
What we want to do is join this table on itself to give the group TariffNumber and RowDescription columns on each row to enable us to group on it. We also want to exclude the GroupHeader Tariff from the Details rows. So we get something like this:
SELECT TariffGroup.TariffNumber AS GroupNumber, TariffGroup.RowDescription AS GroupDescription,
TariffDetail.TariffNumber, TariffDetail.RowDescription, TariffDetail.TariffRate
FROM Tariffs AS TariffDetail
INNER JOIN Tariffs AS TariffGroup ON TariffGroup.TariffNumber = Left(TariffDetail.TariffNumber, CharIndex(TariffDetail.TariffNumber, '.')-1) AND TariffDetail.IsGroupHeader = 0
Now you just need to group on GroupNumber and you're done.

Related

How to show form entries (with conditional logic) that are in the same column

I have a form linked to a sql database. In the database I have a column called "value" and a column called "field_id". When someone send entries, the "value" column shows the values and the "field_id" column shows id number of the field.
The fields are:
-Mobile Phone number
-Promo Code
Is there a way to create a list selecting all the mobile phone number with a specific promo code?
I can't change the form input logic. It's about WPForms plugin for WordPress.
Ok, in WPForms the form entry values are saved in it's own table called wpforms_entry_fields.
We should have a query that would SELECT all the rows with the phone numbers (WHERE field_id = 6 in your case) and then JOIN the rows (basically creating a single row that looks like a pair of 2 rows glued together) by a common reference entry_id so we can filter those joined rows by the conditions we want.
We are getting the same table under two different names by using an INNER JOIN so phone numbers without a code (and codes without a phone number) will not be taken into account.
See more about how INNER JOIN works here: https://www.w3schools.com/sql/sql_join_inner.asp
The SQL query goes something like this:
SELECT phones.value
FROM wpforms_entry_fields AS phones
INNER JOIN wpforms_entry_fields AS codes
ON phones.entry_id = codes.entry_id
WHERE phones.field_id = 6
AND codes.field_id = 5
AND codes.value = 'your_desired_code_here'
What the query does:
it gets all the phone numbers from the meta table
it joins each number with the value of the code from the same entry (that's why we need entry_id)
it filters the values with 'your_desired_code_here'
You can also try SELECT * instead of the first line to see how the rows get joined.

SSRS: Table of group aggregates with grand total

I am using SSRS 2014. My end goal is to get a table that looks like the following:
Project Status # of Projects Oldest Project Avg Project Age
Status 1 27 82 16
Status 2 9 29 6
Status 3 13 112 25
Status 4 33 68 16
Status 5 1 63 63
Status 6 1 27 27
Grand Total 84 112 17
A table like this, including the grand totals, can be done in Excel using pivot tables (this is how the data was originally retrieved...manually...)
If I have the same source data in a table where my columns include projectStatus and projectAge, I could generate a query to get all but the grand totals in SQL:
SELECT projectStatus, COUNT(projectStatus), MAX(projectAge), AVG(projectAge)
FROM projects
GROUP BY projectStatus
If I wanted to add grand totals to that, I could do a UNION with the following query:
SELECT 'Grand Total', COUNT(projectStatus), MAX(projectAge), AVG(projectAge)
FROM projects
Note that the grand totals are calculated off of the entire dataset and not just the grouped data - this mostly applies to the average, because it just happens to work out for the COUNT and MAX columns.
Now, if I am trying to generate this above table in SSRS, it is easy to generate the above table sans grand totals using the former query. However, now how do I add grand totals?
I could instead try a different approach where I use a more generic dataset query like:
SELECT projectStatus AS statusCategory, projectAge AS daysInCurrentStatus FROM projects
And then use aggregate functions in my table and have SSRS do the aggregation itself and provide grand totals on the raw data. I get a new problem now. What is the correct way to set my table up? I am calling grouping by [statusCategory] as "Group1", using scoped aggregate functions like so:
And it correctly generates the grand totals, but now I have a new problem: it is showing the average for each row instead of just one cell per group/scope. Is this something SSRS is meant to do, and if so, how can I do it?
...
You need to mess around a little to get right layout, but you basically need a group header or footer to show the Group aggregates.
if you right click on the lines next to [statusCategory] and select Insert Row > Outside Group - Above it will create a group header for you. Then just add your aggregate expressions in the correct columns like =Count(Fields!projectStatus.Value) then you can just set Row Visibilty on the details row to hide if you dont want to see it.
you should end up with a layout similar to this.
with the middle row (detail) visibility set to false
You're on the right track. You have two Row Groups right now. All you need to do is remove the inner one because it's not grouped by anything. In other words, it's repeating for every row of raw data.
So the Row Group named "Details" - either remove it or in the properties click "Add" and group it by 1. That will collapse those rows and do what you were expecting.

Ssrs reports Windows 2008

I'm fairly new to SQL and I have been issued my first report to build. I have written an SQL query to give me a set of results that I would like to publish in a report.
I have unioned about 20 small queries all containing the correct amount of columns. One column is a misc column with about 15 different descriptions in (this is what I want to count).
I have uploaded my data set and now want to be able to choose a cell in my report to bring back a certain description.
At the minute I'm using
=count(fields!misc.values)
and it's giving me the whole count, about 200.
I would like to know if there is any kind of "where clause" (filter) which I can use to state which description results I want to bring back.
You can use am expression to count the misc.value you need. It will work like a count using a where clause:
=Sum(iif(Fields!misc.Value ="Some description",1,0))
Example:
For count the FSMethod with MethodOne as value I used this expression:
=Sum(iif(Fields!FSMethod.Value ="MethodOne",1,0))
Note the expression sums by 1 if the FSMethod.Value is MethodOne.
For count the rows with FSMethod column with MethodTwo value.
=Sum(iif(Fields!FSMethod.Value ="MethodTwo",1,0))
Let me know if this can help you.

Add each row in a single cell

I have a requirement in ssrs report for display data like this.
I have to show 2 two rows data in one row in ssrs as shown below. Row count is unknown.
Please check another example.
Max two cell in one row in ssrs. I have to do this dynamically because I don't have any fix count in my data base table. If my table contain 3 rows it will display like first example but it it has 6 rows then it will looks like 2nd example.
Any suggestion how I can achieve.
The only way I know to do this left-to-right, top-to-bottom flow style is to sort of hack it in with lists. To my knowledge, the built-in controls do not directly support it.
First add a couple of columns to the query output to assign row and column numbers to each data row. (Change the order by clause as appropriate)
ceiling(row_number() over (order by AddressField) / 2.0) RowNumber
(row_number() over (order by AddressField) + 1) % 2 + 1 ColumnNumber
Now add a list to the report. Group by the RowNumber field. Within that list, add two more lists side by side. They will use the same dataset as the parent list. These will represent the cells. The left 'cell' will be a list with a filter ColumnNumber = 1. The right 'cell' will be a list with filter ColumnNumber = 2.
Now add textboxes within each 'cell' to contain the address data and format them as you desire.

Any recommendations as to grouping this table in Reporting Services?

I'm just starting with Reporting Services so please take that into consideration.
I'm trying to make a report that groups by Nominee. I also want to group by Nominator i.e. so that if a Nominee has the same Nominator twice then it displays only ONE row instead for two and it increments field Number of Nominations (I get I need to use COUNT() here) and adds the total points of both (which I suspect I need to use SUM() on).
This is my table (on top) and the one I want to display on the bottom.
http://i.imgur.com/DZNoB.png
Notice on the top table that Janine and Rose have 2 different nominations with the same Nominator, therefore on the bottom table they display counts 2 on number of nominations and the sum of the points for both of the nominations.
So far I've tried this:
http://i.imgur.com/LPyiY.png
How can I make it so I can include name, Dept, points and number of nominations in between groups? I've tried inserting text boxes but it doesn't work. Is there a better way to do this?
Also I'm using a Tablix
Just create one group by option that takes the Nominee Name / ID, and display the name.
Within the details section add each nominator name. In the footer of the Nominee Name group just add =COUNT(Fields!NominatorID.Value)
It would end up with something like this:

Resources