Build reports dynamically in ssrs - reporting-services

I have data in my database table which looks similar to the data below :
Time Name Sales
Aug-11 A 33
Aug-12 B 34
Aug-13 C 31
Aug-14 D 39
Sep-11 A 99
Sep-12 B 34
The requirement is that I need to build a report for A details ,another report for B details ,and another for C details and so on. There Could be a D and E added to the database table next month and some more data the month later...
I want to know if there is a way that I can create the reports dynamically , rather than creating a report for A, B and C now and then going into the report and creating another report for D and E next month and soo on..
Please let me know.

Create a report with a parameter #Name , Create a Drop down List using query something like
SELECT DISTINCT Name
FROM Table_Name
for user to select A, B or C and in parameter properties you can choose it to be a multiple selection and create a query something like
SELECT Time, Name , Sales
FROM Table_Name
WHERE (Name IN (#Name_Pram))
You will have to create 2 Data sets one for the drop down list from where users will select Name parameter, selected value(s) will be passed to the above query , One report will show details for any selected values.

Related

Populate Dynamic table columns based on parameter drop down values selection in SSRS report

*Scenario:
We have one table with below columns: I need to use ONLY this table
ID
ACCOUNTID
STATUS
COMPARE
MODFIEDUSERNAME
FILENAME
FILEDESP
1
A2
IN
MATCH
Sam
abc
wew
2
A4
OUT
MATCH
Ken
xcr
wew
3
A2
IN
MISMATCH
Roy
abc
wew
4
A3
OUT
MISMATCH
Roy
xcr
wew
In the report we should have a drop down(SingleValue) for COMPARE column with values(MATCH/MISMATCH) where user can select either of one value.
If User select MATCH Option then Report should display a dropdown(MultiValue)(ReportFields Data Set) with these columns :
ID ACCOUNTID STATUS
If User select MISMATCH Option then Report should display a dropdown(MultiValue) (ReportFields Data Set) with these columns :
ID COMPARE MODFIEDUSERNAME FILENAME FILEDESP
Basically , populate column names dynamically based on MATCH and MISMATCH selection and when user clicks on View Report, Report should display respective column data.
I created the Data Set -ReportFields as below:
SELECT 1 ID, 'Id' AS ColumnName UNION
SELECT 2 ID, ACCOUNTID AS ColumnName UNION
SELECT 3 ID, 'Status' AS ColumnName UNION
SELECT 4 ID, COMPARE AS ColumnName
I created two parameters: #Compare and #ReportFields
Problem:
Need the logic to populate Dynamic columns based on user selection from first dropdown with (MATCH/MISMATCH) Values.
Your example is a little confusing but I'll show you a typical scenario which should give you enough info to solve your problem.
If we have a table of, say, fruit & veg sales and we want the user to select either fruit or veg from the drop down, then have a seconds drop down that they can chose individual items(s) from then we can do this.
The table looks like this. (I've included some sales numbers here for simplicity but these could easily be in another table).
Category
ItemName
Month
Amount
Fruit
Apple
Jan
10
Fruit
Apple
Feb
20
Fruit
Apple
Mar
30
Fruit
Orange
Jan
40
Fruit
Orange
Feb
50
Vegetable
Carrot
Jan
15
Vegetable
Peas
Jan
16
Vegetable
Cucumber
Jan
17
Vegetable
Carrot
Feb
18
The dataset for our first parameter would be
SELECT DISTINCT Category FROM myTable
This will give us 'Fruit' and 'Vegetable'
We assign this as the available values of our first parameter which we will call pCategory
Our second dataset would be
SELECT DISTINCT ItemName FROM myTable WHERE Category IN(#pCategory)
I've used IN here so that if pCategory is multi-value, it will correctly select from both categories.
We assign this seconds dataset as the available value for our seconds parameter which we will call pItems. This shoudl be a multi-value parameter. We could also assign this same dataset to the default values for this parameter so all items are selected by default.
Finally our last dataset will get some data to show in a table/matrix and will look something like this
SELECT ItemName, Month, SUM(Amount) AS SalesAmount
FROM myTable t
WHERE t.ItemName IN(#pItems)
NOTE: When you specify a parameter name in a dataset query, it must match the name of the parameter name in your report design exactly, it is case sensitive.

Populating with '0' when Data in SSRS Does not exist

I'm trying to create a report in SSRS where I have a matrix, which has gender as the column headings and specifically defined agegroups as the rows. The report is sorted by date (ie, the records being displayed are filtered by the modifedAt value). My problem is that i wish for all of the age group categories to be displayed, even if the dataset does not return any data for that row.
So, for example, if i set the date to be a date where there are no db rows where there are Age5-16 children in - I still want to display the category name, but just have the cells related to that row to display '0'. Instead, the report just drops the whole row because, obviously the query returns no data.
Is the solution to have a separate dataset that brings back the entire list of categories and then somehow fit them together? I'm stuck here so any help is appreciated!
I can think of a few ways to do this:
DataSet level
Instead of just returning the relevant data in the underlying data in the DataSet, include all the categories you want to display in all cases.
e.g. For a database query it might be the difference between an inner and left join, i.e. going from something like:
select *
from AgeGroup
inner join MyData on ...
to:
select *
from AgeGroup
left join MyData on ...
So the report always has all the age groups to display. Where there are NULL values, just display 0.
I think this is the best option if you have control over the DataSet - you won't have to update your report at all, with luck the actual DataSet changes should be minimal, there is still only one DataSet call, and it's by far the simplest to maintain.
Hard code groups into the report
Here you include a table header row for each group you want to display, so these are always displayed in all cases.
Here you have some sort of conditional expression to display the values, e.g. For each group row it will be tailored to that group:
=Sum(IIf(Fields!AgeGroup.Value = "5-16", Fields!Amount.Value, Nothing)
This is not too flexible and will need updates as you change groups, and doesn't have as many options for layout. There is still only one DataSet call, so that is a plus.
Subreports
You can have a parent DataSet that displays one row for each age group, then embed a subreport in each row that displays the data you want for that row.
This allows you flexibility in layout but it will add complexity to the report(s) and will mean that you make a lot of DataSet calls that could be avoided with other options.
I know this is old, but I wanted to elaborate on Ian's section 1 above using joins at the dataset level. (His answer was super helpful to me for a report I'm working on.)
per op:
Is the solution to have a separate dataset that brings back the entire list of categories and then somehow fit them together?
That is how I've handled it successfully, but you can do so without actually creating a separate dataset by using common table expressions (or temp tables, of course).
For these example tables:
AGE_Table
ID Group Group_Desc Toys
1 A 00-10 Teddy Bear
2 B 11-20 Video Game
3 C 21-30 Sports Car
4 D 31-40 Mansion
5 E 41-50 Jewelry
People_Table (filtered for whatever date)
ID Name Age Gender Age_Group
1 Ariel 07 F A
2 Brandon 23 M C
3 Chelsea 27 F C
4 Derek 06 M A
You want to see 2 results for the 00-10 row, 2 for the 21-30 row, and then still see rows for the other age groups even if there aren't any results.
We want to create a dataset with all the different age groupings and then join on it. Behold a solution using common table expressions:
with CTE_Age AS
(SELECT Distinct Age_Group from AGE_Table)
SELECT ID, Name, Age, Gender, CTE_Age.Age_Group FROM People_Table
RIGHT JOIN CTE_Age ON
People_Table.Age_Group = CTE_Age.Age_Group
This will return:
ID Name Age Gender Age_Group
1 Ariel 7 F A
4 Derek 6 M A
NULL NULL NULL NULL B
2 Brandon 23 M C
3 Chelsea 27 F C
NULL NULL NULL NULL D
NULL NULL NULL NULL E
Once you have that in your dataset, you can change NULL values to 0 on the report builder side -- I think in 2008R2 the default is just blank.

N or more continuous year range

I have to create a report using MySql DB where more than 4 tables are involved. I have one table (S1) with S1_ID and S1_Year_Range (strings like 2001-2002) and another table (S2) with S2_ID(PK), S2_Customer_ID, S1_ID (FK) and other fields for other conditions that can appear in Where clause of my query. There can be more than one row in S2 with the same S2_Customer_ID but different S1_ID. My query is to create a report using VB.net and ask users to enter two values; one number for how many continuous years or bigger (like >= 5 years), and a year range value (like 2011-2012) which is the highest value in the list for all customers.
My report lists customer names (by joining the above query with another table), customer rank and all year range values (highest at the bottom) for that customer in one column for each customer. Any help for this query would be appreciated.
Data and results could be like the following:
S1:
(S1_ID....S1_Year_Range)
(1......2000-2001)
(2......2001-2002)
(3......2002-2003)
(4......2003-2004)
(5......2004-2005)
etc
S2:
(S2_ID.....S2_Customer_ID.....S1_ID)
(1....1....1)
(2....1....2)
(3....1....3)
(4....2....2)
(5....2....3)
(6....2....5)
(7....3....2)
(8....3....3)
(9....3....4)
(10...3....5)
(11...4....3)
(12...4....4)
(13...4....5)
etc
when number 2 and year range (2003-2004) is entered by the user, the result should be the following:
customer 3 with 3 year range values (2003-2004, 2002-2003, and 2001-2002) and customer 4 with 2 year range values (2003-2004 and 2002-2003):
cname3
2001-2002
2002-2003
2003-2004
cname4
2002-2003
2003-2004
I hope you can see the columns of the report correctly.
I finally created a complex query to solve my problem. In the following query, I encoded the user year range value as '2010-2011' and number of continuous years as 14. Also a tiny difference with the question is the table names; table CSP here is the same as table S2 in my question but field names are the same as those in my question.
SELECT CSYWFY.S2_Customer_ID, COUNT(CSYWFY.S2_Customer_ID)
FROM (SELECT S1F.S1_Year_Range, S2.S2_Customer_ID , COUNT(S1F.S1_Year_Range) FROM CSP as S2 INNER JOIN S1 as S1F ON S2.S1_ID = S1F.S1_ID WHERE '2010-2011' IN (SELECT S1N.S1_Year_Range FROM CSP as S2N INNER JOIN S1 as S1N ON S2N.S1_ID = S1N.S1_ID WHERE S2N.S2_Customer_ID = S2.S2_Customer_ID ) GROUP BY S2.S2_Customer_ID ASC , S1F.S1_Year_Range DESC ) CSYWFY
GROUP BY CSYWFY.S2_Customer_ID
HAVING COUNT(CSYWFY.S2_Customer_ID) > 14
HTH

Access 2003 - Running an update query based on select query results

I currently have a subform that displays a select query. I want to update all the records of Table B that are showing in the subform with information from the form. The subform is not necessary. I was just using it to make sure my select query was displaying correctly.
Table A has 3 columns (OID, Project_Number, Landowner)
Table B has 4 columns (OID, PhoneNum, Address, Year)
These tables have a one to many relationship. One OID in Table A relates to many in Table B
Table A
1 A10 Bill
2 B10 Sally
3 A10 Bill
Table B
1 555 123 blah st 2012
1 2013
2 111 456 aaa st 2012
3 2012
The form allows the user to enter information that populates Table B.
The subform displays a list of records where Project_Number, Landowner, and Year are equal to the record showing on the form
For example. If the form is showing
1 A10 Bill
the subform is showing
1 A10 Bill 2012
3 A10 Bill 2012
When I click a save command button I would like it to run the update query but I'm having issues with the SQL command.
My Select query is as follows:
SELECT B.Project_Number, A.LANDOWNER, B.Year
FROM A INNER JOIN B ON A.OBJECTID = A.OBJECTID;
The subform is setup
Link Child Fields: Project_Number; Year; Landowner
Link Master Fields: B.Project_Number; Year; A.Landowner
I would like:
UPDATE B.PhoneNum, B.Address, B.Year
WHERE items found in my subform
WITH information from my form
Is it easier to forget the subform and do it all through a single update query?
UPDATE B SET B.phonenum = [New_Info]![PhoneNumCtrl], B.Address = [New_Info]![AddressCtrl]
WHERE [A]![Landowner] = The same landowner as the OID selected, [A]![Project_Number] = The same project number as the OID selected, [New_Info]![Year] = [B]![Year]
Thanks in advance for any help!
Everything is working now. I wanted to add to djphatic's answer.
When doing this make sure to add [Forms]![formname]![controlname]
Depending on where the controls are on your form you may need to change the control reference.
Use the query builder GUI to create a select query which has the columns you wish to update and filter the records using the controls on your form. Once you have this you can change the query to an update query and set the values the controls on your form.
UPDATE B
SET B.phonenum = [formname]![controlname], ...
FROM B JOIN A ON B.OID = A.OID
WHERE A.PROJECTID = [formname]![controlname]
AND B.YEAR = [formname]![controlname]

Excel VBA Report, Selecting Cells by a criteria

I have this Excel
now i want to make some reports using a VBA Macro
Report 1 (select all tasks)
Select the number of total tasks no matter if they are completed or not
IMPORTANT! Keep in mind that here are 5 tasks, in another excel may be 20 30 , but all have the same format C6 - task_id, D6 - task_name, E6 task_name ... and so on
Report 2 (select all WHERE completed is 100%)
Select the number of total tasks where completed column is 100%
IMPORTANT! Keep in mind that here are 5 tasks, in another excel may be 20 30 , but all have the same format C6 - task_id, D6 - task_name, E6 task_name ... and so on
Report 3 (select all users and retrive information about their productivity)
Here basicaly i need something like
SUM(I6:I10) - SUM(K6:K10) WHERE task_given_to = 'OM'
SUM(I6:I10) - SUM(K6:K10) WHERE task_given_to = 'MN'
SUM(I6:I10) - SUM(K6:K10) WHERE task_given_to = 'NM'
IMPORTANT! Keep in mind that here are 5 tasks, in another excel may be 20 30 , but all have the same format C6 - task_id, D6 - task_name, E6 task_name ... and so on
Any help with that?
I must say, in SQL it would be easy ...
Is there any requirement to use VBA ? Unless there is something I am missing, a simple pivot table would be able to do that.
Just put the task name as the row field.
Apply a filter on completion.
User as row field, productivity as data, task type as column.
Isn't it what you are trying to achieve ?
Oh and FYI if this does come from Access you can use MS Query.
Data => Other sources => MS Query => Access database
Then you can just use an SQL query to retrieve data. I'd then make 3 data sheets with 3 different queries and 3 report sheets which would format the data to a more report-like format.