Column and Row grouping in SQL Server Reporting Services 2008 - sql-server

This is the desired result I need to populate as a report, where xx is number of people.
I have a table which has fields like:
----------
table1
----------
id
state
year(as Quarter)
gender
I need to determine the count from id and populate as a report. The year is like 20081, 20082..20084 (in quarter).
I have created a dataset using this query:
SELECT STATE,GENDER,YEAR,COUNT(*)
FROM TABLE 1
GROUP BY STATE,GENDER,YEAR
From this query I could populate the result
ex: ca, m , 20081,3
ny, f , 20091,4
From the above query I could populate the count and using group by(row) state(in ssrs).
I need to group by (column). From the gender I get and by year.
How do I take the column gender and make it has Male and Female column?
Do I need to create multiple dataset like passing
where gender = 'M' or gender = 'F'
so that I could have two datasets, one for Male and One for Female? Otherwise, is there any way I could group from the Gender field just like pivot?
Should I populate result separately like creating multiple dataset for Male 2008, Female 2009 or is there any way I could group by with the single dataset using SSRS Matrix table and column grouping?
Should I resolve it at my Query level or is there any Features in SSRS which could solve this problem?
Any help would be appreciated.

Your SQL query looks good, but I would remove the quarter with a left statement:
select state, gender, left(year,4) as [Year], count(ID) as N
from table1
group by state, gender, left([year],4)
Then you have a classic case for a Matrix. Create a new report with the Report Wizard, choose "Matrix", then drag the fields across:
Rows: State
Columns: Year, Gender
Details: N
This should give you the required Matrix. Then replace the expression of the textbox with the Gender from
=Fields!gender.Value
to
=IIF(Fields!gender.Value="M", "Male", "Female")
Good luck.

Related

How do I create a powerbi report to show the same results as a sql group by query

I have a sql server table. I have included a few of the columns from that table below
status_id
region
location
1
South State
Sun City
2
South State
Sun City
3
North State
Rain City
4
North State
Sun City
There are lots of statuses for each city. However there should only be one region for each city. In the example above there are 3 statuses for Sun City, but they are in 2 different regions.
In sql I can easily find which cities have this conflict with this query:
select count(distinct region), location
from status
group by location
having count(distinct region) > 1
This will return:
count
location
2
Sun City
My question is how do I reproduce this query in powerbi? Note that I cannot make any changes to the sql server data. I just need to report on the conflicting data.
You can do this without writing any DAX by putting the location column into a matrix visual and adding region as the values field and setting the aggregation to Count (Distinct) using the dropdown and then using the filters to pick when these are greater than one.
Of course, you can write a calculated table with DAX too.
MultiRegions =
FILTER (
SUMMARIZECOLUMNS (
'status'[location],
"count", CALCULATE ( DISTINCTCOUNT ( 'status'[region] ) )
),
[count] > 1
)

SSRS - How to reference a specific field's value based to be able to use it in another field?

I have a dataset which gives me all the results I need in order to formulate my table in my report.
Dataset Returns this:
District Location ChlorineValue
-------------------------------------------
Belize1 WTPA 3.4
Belize1 WTPB 2.6
Belize1 Sandhill Road 0.5
OK so currently in my SSRS report I have when it gets to the row with "Sandhill Road" under "Location", it displays "Sandhill" as the "District".
What I want to do is in the SSRS Tablix, I want it to display two rows under "Sandhill" (my SSRS report is grouped by the "District" column, a Row Group) with the values for "WTPA" and "WTPB" under the "Chlorine Value" column.
Basically I want my result to be:
District Location ChlorineValue
-------------------------------------------
Belize1 WTPA 3.4
Belize1 WTPB 2.6
Sandhill WTPA 3.4
Sandhill WTPB 2.6
I've read about using Variables but I can't get the Report Properties to reference my dataset which contains the values.
I think you'd need to do this in the SQL with a UNION:
SELECT District, Location, ChlorineValue
FROM T1
WHERE T1.Location NOT LIKE 'SANDHILL%'
UNION
SELECT T1.Location, T2.Location, T1.ChlorineValue
FROM T1
JOIN (
SELECT *
FROM T1
WHERE T1.Location NOT LIKE 'SANDHILL%'
) T2 ON T2.District = T1.District
WHERE T1.Location LIKE 'SANDHILL%'

Reports based on multiple tables MSAccess

I designed a report(salary slip) with many controls(text boxes) in MSAccess 2016.
There are 2 tables Employee details and salary details.
Some controls that need data from employee details table and some from salary table.
I have 2 primary keys
Sl.No
Employee id
for both the tables.
and I have connected the employee id through relationship.
How to specify the expression in the text boxes so that i get the record that matches both the table?
Use a query as record source of your report instead of a table. Then you don't need any expressions in the textboxes, just the column names. I usually give the query the same name as the report but with another prefix. E.g. for report rptSalary the query is named qrptSalary.
SELECT * FROM
Employee E
LEFT JOIN SalaryDetails S
ON E.EmployeeID = S.EmployeeID
In the report, you can insert group headers and footers. You would use EmployeeID as grouping column. Then you can place the employee fields in the employee group header, the salary details in the details section and any sums in the group footer.

Filter Columns based the condition of a Row

I have the following Matrix in SSRS 2008 R2:
What I would like to do is only show columns where the "FTE" row has a value. (Marked with red circles). I've tried the filter and show/hide options based on expressions in the Column Properties, but I can't figure out how to only reference the rows when "category"="FTE". My data looks like this:
tblPhysicians
employee_id last_name ...
102341145 Smith
123252252 Jones
tblPhysiciansMetrics
id fy period division_name category_name employee_id
123 2014 1 Allergy Overhead 123456
124 2014 1 Allergy Salary 125223
125 2014 1 Allergy FTE 1.0
query
SELECT * FROM
tblPhysicians
INNER JOIN tblPhysicianMetrics
ON tblPhysicians.employee_id = tblPhysicianMetrics.employee_id
WHERE
tblPhysicianMetrics.division_name = #division_name
AND tblPhysicianMetrics.fy = #fy
AND tblPhysicianMetrics.period = #period
Notice that the rows in my Matrix is just the category_name, so I can't just hide when category_name = "FTE", that's not really what I want. What I really need is some way of saying, "For rows where category_name = "FTE", if the value is not set, don't show that column". Is this possible?
An alternative would be to not even get those in the query, but as with the filtering of the matrix, if I simply add "AND tblPhysiciansMetrix.category_name = 'FTE'" to the WHERE clause, my entire data set is reduced to only those records where category_name is FTE.
Any help is much appreciated!
Update: added definition of Matrix to help:
You need to set the column visibility with an expression that checks all underlying data in the column for the FTE category.
I have a simple dataset:
And a simple matrix based on this:
Which looks exactly as you expect:
So in the above example, we want the Brown column to be hidden. To do this, use an expression like this for the Column Visibility:
=IIf(Sum(IIf(Fields!category_name.Value = "FTE", 1, 0), "last_name") > 0
, False
, True)
This is effectively counting all the fields in the column (determined by the last_name scope parameter in the Sum expression) - if this is > 0 show the column. Works as required:
CAVEAT I'm not 100% sure how you are grouping this data in the matrix. It isn't 100% clear from your description. Let me know why this doesn't work (if it doesn't and I'll update my answer accordingly.
I've replaced the column employee_id with the name value for my answer, to keep my explanation simple.
Add this nested IIF() to the visibility property of your Matrix's column.
=IIF(Fields!category_Name.Value="FTE" ,IIF( Fields!value.Value >= 0, True,False),false)
It will check both the value of the the category and the 'FTE' in that row's cell.

How to show data in column in SSRS

I'm using SSRS for my reporting, my reporting solution is in Visual Studio 2008 Business Intelligence Development Studio.
I have a report in which the data should be displayed in this format.
I have added a Column Group in my table which is having the values of Customer Name and details, the data is coming fine in the vertical format i.e column after column.
My Issue :
There should be only three columns in each row, after three records the next row should begin and again not more than three records should be displayed as shown in the image above.
My attempts :
I tried to add a row group and in that gave the expression
= Ceiling(Fields!Row_Count.Value/3)
here Row_Count is a field which is coming from my query which holds the serial number of the records.
My SQl Query
SELECT Row_Number() over(order by table_ID) AS Row_Count, Field_1,Field_2 from MyTable
In my Column group i have Customer Name and in my Row Group i have other details of the customer. The data is getting populated column wise but the issue is its not breaking the current row after three records.
Below is my table of report.
You were on the right track. Say you have data like this:
I have created a tablix like this:
The Row Group expression is:
=Ceiling(Fields!Row_Count.Value / 3)
This works together with the Column Group expression to split over three columns:
=(Fields!Row_Count.Value - 1) Mod 3
The other thing to note compared to your tablix is that CustomerName is not in a table header row, but rather there are two row header rows, one for CustomerName and one for Details.
This is looking OK to me, obviously you can format to taste:

Resources