I have the following report in SSRS:
EmployeeNumber EmployeeName Team Revenue
1 Jack AA-JP €100
2 Mandy CY-JP €150
1 David PA-DK €300
The query behind is :
SELECT *
FROM T1 (NOLOCK)
WHERE YearNo IN (#dd_YearNo)
AND (WeekNo BETWEEN #txt_WeekNoFrom AND #txt_WeekNoTo )
AND LEFT(Team,2) IN (#dd_Group)
AND Team IN (#dd_Team)
AND SalesPerson IN(#dd_SalesPerson)
The parameters are the result of a query each one.
I want to format the Revenue column to set ¥ for employees who belongs to teams ending with JP
and the others will be € by default
In the Design part of your SSRS package, right click on Revenue cell and go to Text Box properties:
Go to Number > Custom :
In the expression editor :
=IIF(RIGHT(Fields!Team.Value,2)="JP","¥ #,##0","€ #,##0")
Related
*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.
I am creating a SSRS list report based on this SQL:
select name, job_id, job_title from HR
name job_id job_title
--------- --------- ---------
Mike Jones 123 Manager
Mike Jones 775 Analyst
Patty Bea 562 Director
Patty Bea 964 Deputy CFO
After creating the design and previewing the report, I get 4 pages based on my SQL results.
When a name has more than one jod_id and job title, I would like to list both on one preview page of the SSRS report.
Your preview looks like your desired result - 'I would like to list both on one preview page ' - rather than the 4 page current result.
If you haven't done it - you'll want to only GROUP on the name and use a LOOKUPSET to get all the values associated (and use a JOIN to combine them into a single string):
=Join(LookupSet(Fields!name.Value, Fields!name.Value, Fields!job_id.Value, "DataSet1"), ", ")
The LookupSet looks up all the results that match the name field (argument 1) to the name field of the dataset (argument 2) and gets the job_id field (argument 3) from DataSet1 (argument 4).
For the job_title field, do the same but change the job_id field to job_title.
I want a interactive sorting in SSRS matrix report. From database we are getting 3 columns -PrimaryKey,Columns and Value.
We are grouping rows by Primary Key and grouping column by Columns and use Value as data.
My Matrix Report -
ID [Columns]
[Primary Key] Values
Output of the Matrix report -
ID FirstName MiddleName Lastname
1 Rajiv Jha Sharma
2 Prem Kumar Bose
3 Usha Shamila Praveena
I am able to use the interactive sorting on ID because ID is group by rows but I want to use the interactive sorting on dynamic cloumns values like FirstName,MiddleName and LastName.
Expected result when we interactive sort on Lastname
ID FirstName MiddleName Lastname
2 Prem Kumar Bose
3 Usha Shamila Praveena
1 Rajiv Jha Sharma
Thanks for any Help.
Are you using the report wizard to build this? You should be able apply the interactive sort using the properties menu on the column groups.
By adding an interactive sort button to a column header you can allow a user to click the column header and sort the parent group rows in a table or matrix by the value displayed in that column. The order of child groups remains unchanged.
To add an interactive sort button to a column header to sort groups:
In a table or matrix on the report design surface, right-click the text box in the column header for the group to which you want to add an interactive sort button.
Click Text Box Properties.
Click Interactive Sort.
Select Enable interactive sort on this text box.
In Sort, click Groups.
From the drop-down list, select the name of the group that you are sorting. For groups based on simple group expressions, the Sort by value is populated with group expression.
For more info, see this article: http://technet.microsoft.com/en-us/library/cc627509(v=sql.100).aspx
Quite an old question, but I stumbled upon similar problem recently.
Though SSRS does not allow you to add interactive sorting on dynamic columns in a matrix, you can simulate similar behaviour. I've figured out a method, which require the report to fire itself (through go to report action) sorted on desired column.
I will use a bit more complicated example to show the full functionality of this solution.
Imagine an online bookstore, which would like a report showing their customers (rows), number of books (values) and total value of books (values), which they bought, by category – Fiction/NonFiction in my example (columns). Of course they want to see their best customers, so the sort will be descending.
Example data that we are getting from the database:
UserID Columns BooksCount BooksValue
AliBaba Fiction 2 25.96
AliBaba NonFiction 4 112.00
ThomasJefferson Fiction 3 36.83
ThomasJefferson NonFiction 1 46.80
BillCosby Fiction 10 536.47
BillCosby NonFiction 2 26.87
The report will look like this:
[Columns]
Books Count Books Value
[UserID] Values Values
I would like the report to be able to sort by “Books Count” or “Books Value” for any Column. Here are the steps to follow:
You need to add parameters that will store the name of the column to sort on - #SortColumn and the metric name (counts or values) to sort on - #SortMetric.
Go to “Books Count” textbox and add action "Go to report" specifying the same report. Add #SortColumn parameter with a value from [Columns] field in the underlying dataset. Add #SortMetric parameter with value set to “BooksCount”. Similar for “Books Value” textbox.
You can adjust the column header text with following expression, which will show the user on which column data is sorted:
= IIf( Parameters!SortColumn.Value=Fields!Columns.Value And Parameters!SortMetric.Value = "BooksCount" ," ^","")
This was for “Books Count”, you can add similar for “Books Amount”
Finally the magic that happens on the database site. Source table is named [Sales]. Apart from the sorting, below code allows to select only top N rows if your dataset is larger.
You can create a dataset using this code or better create a stored procedure. And join report parameters with dataset parameters.
DECLARE #TopN INT = 50
;WITH Users_Sorted AS
(
SELECT
UserID
,ROW_NUMBER() OVER (ORDER BY
CASE #SortMetric
WHEN 'BooksCount' THEN Sales.BooksCount
WHEN 'BooksValue' THEN Sales.BooksValue
END DESC) AS ROWNO
FROM Sales
WHERE
Sales.Columns = #SortColumn
)
,Sales_MAIN AS
(
SELECT
Sales.UserID
,Sales.Columns
,Sales.BooksCount
,Sales.BooksValue
,ISNULL(Users_Sorted.ROWNO,
ROW_NUMBER () OVER (PARTITION BY Sales.Columns ORDER BY Sales.UserID ASC)
) AS ROWNO
FROM Sales
LEFT JOIN Users_Sorted ON Sales.UserID = Users_Sorted.UserID
)
SELECT * FROM Sales_MAIN WHERE ROWNO <= #TopN ORDER BY ROWNO
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.
A long time reader. A great wealth of info on this site.
Hopefully this isn't a dumb question, but I've been struggling on how to get the correct totals in my report.
I'm having issues with simple totals. I have a report that takes the difference of two numbers and shows the result, with the results being both negative and positive. At the bottom of the report I want a total sum of the difference. The totals are not even close for some reason.
Here's my data:
Correct Data
Specialist Total Sales Budget Difference
DICK "$35,174.00" "$63,530.00" "($28,356.00)"
NATHAN "$16,193.00" "$40,000.00" "($23,807.00)"
PAUL "$52,096.00" "$55,000.00" "($2,904.00)"
STEVE "$31,185.44" "$66,700.00" "($35,514.56)"
**Totals: "$134,648.44" "$225,230.00" "($90,581.56)"**
Incorrect Data that is in my report
Specialist Total Sales Budget Difference
DICK "$35,174.00" "$63,530.00" "($28,356.00)"
NATHAN "$16,193.00" "$40,000.00" "($23,807.00)"
PAUL "$52,096.00" "$55,000.00" "($2,904.00)"
STEVE "$31,185.44" "$66,700.00" "($35,514.56)"
**TOTALS: "$134,648.44" "$225,230.00" "$71,118.44"**
As you can see, the data shows the total differece as $71,118.44 when it should be ($90,581.56).
Here is my expression to get the result of the Difference:
=Sum(Fields!TotalSales.Value)-Fields!Budget.Value
I right clicked on the text box and selected "Add Total" to get a Grand Total for the Difference field. I also tried this suggestion:
=Sum(Fields!TotalSales.Value)-Sum(Fields!Budget.Value)
And this:
=ReportItems!textbox14.Value - ReportItems!textbox15.Value
Another thing to mention is there is grouping on Specialist. The Total Sales field is a Group total for their sales for that particular month. The Budget field is a single field outside of the group.
This seems like a no brainer that it should work. Maybe someone can give me some guidance on this.
Thanks in advance.
EDIT:
Thanks for the help, but unfortunately the issue is more complicated than that :) I should have been more clear on that. I'm pulling data from 3-4 databases and they don't have a common field to link on. What I'm using a Row number to reduce duplicate subtotals and set them to 0. I using a rownumber on the Budget number, but the data I was getting back was bogus. Here's the data I have:
Name Team SubTotal Budget
SCOTT Vikings 202 25000.00
SCOTT Vikings 1890 25000.00
SCOTT Vikings 5167 25000.00
SCOTT Vikings 20256 25000.00
SCOTT Vikings 0 25000.00
SCOTT Vikings 0 25000.00
And here's the data I want to have:
Name Team SubTotal Budget
SCOTT Vikings 202 25000.00
SCOTT Vikings 1890 0.00
SCOTT Vikings 5167 0.00
SCOTT Vikings 20256 0.00
SCOTT Vikings 0 0.00
SCOTT Vikings 0 0.00
If the budget number repeats more than once, I want it to be 0. I think this is the reason my totals aren't showing correctly in SSRS. I'm calculating the Difference field by taking the GrandTotal of the Salesman's subtotals and subtracting them from the Budget Field that was put into the group footer (since I'm new I can't post images, sorry. Here's the hyperlink)
http://i55.tinypic.com/124jw2u.png
Here's my SQL Statement also:
WITH InvoicedAndPaid
AS
(
SELECT KEY1
,ltrim(rtrim(CustomText01)) as CustomText01
,ROW_NUMBER() OVER(PARTITION BY DocNo ORDER BY DocNo) AS RowNumber
,SubTotal
,OrderDate
,INVOICEDATE
FROM DocumentHeadersItems AS AA
JOIN SorArCombined AS BB
ON AA.DocNo = ('AA' + BB.CustomerPoNumber)
JOIN CONTACT1 AS CC
ON AA.SoldToCMAccountNo = CC.ACCOUNTNO
WHERE CreatedBy != 'NOAHDM'
AND KEY1 IN (#org)
AND SubTotal != 0
AND LEN(INVOICE) > 0
AND
(
(
CUSTOMER = 'QAA'
AND (INVOICEDATE IS NOT NULL)
AND (DATEPART(MM,INVOICEDATE) = DATEPART(MM,#start))
AND (DATEPART(YYYY,INVOICEDATE) = DATEPART(YYYY,#end))
)
OR
(
CUSTOMER != 'QAA'
AND (YearInvBalZero > 0)
AND (YearInvBalZero = DATEPART(YYYY,#start))
AND (MonthInvBalZero = DATEPART(MM,#start))
AND (YearInvBalZero = DATEPART(YYYY,#end))
AND (MonthInvBalZero = DATEPART(MM,#end))
)
)
)
SELECT bb.team_id
,bb.specialist_id
,dd.Budget
,cc.team_name
,KEY1
,CustomText01
,CASE WHEN RowNumber = 1 THEN SubTotal ELSE 0 END as SubTotal
FROM InvoicedAndPaid as aa
join SalesReporting.dbo.team_members as bb
on rtrim(aa.CustomText01) = rtrim(bb.specialist_name)
join SalesReporting.dbo.team_master as cc
on bb.team_id = cc.team_id
join SalesReporting.dbo.sales_goals as dd
on bb.specialist_id = dd.specialist_id
WHERE dd.time_span LIKE 'M%'
AND dd.month = DATENAME(MONTH,#end)
AND dd.Org = aa.KEY1
AND cc.team_name in (#team)
AND dd.period_no = DATEPART(MM,#end)
ORDER BY team_name, CustomText01
Does this help out a little? I'm trying to avoid doing a Stored Procedure because I'm fairly new at SSRS and SQL Server.
One option would be to calculate the total sales in the SQL Server query that is used in SSRS dataset. Following example shows a sample. The sample was created based on an assumption of how I envisioned the table might be. The report was created in SSRS 2008 R2 and database used was SQL Server 2008 R2.
Assuming that the source table is as shown in screenshot #1. The table is not normalized but it is shown here just for an example.
The query for the report database would be as shown in screenshot #2. The query is also given under SSRS Dataset Query section.
Report would be designed as shown in screenshot #3. Expression in section a would =Fields!TotalSales.Value - Fields!Budget.Value and Expression in section b would be =Sum(Fields!TotalSales.Value, "SalesData") - Sum(Fields!Budget.Value, "SalesData").
Screenshot #4 shows report execution.
Hope that helps.
SSRS DataSet Query:
SELECT Specialist
, SUM(Sales) AS TotalSales
, SUM(DISTINCT(Budget)) AS Budget
FROM dbo.SalesData
GROUP BY Specialist
Screenshot #1:
Screenshot #2:
Screenshot #3:
Screenshot #4:
In this rare case, I had to put in a footer and reference the sum formulas to the actual text boxes. Very weird that this worked but the regular expressions did not.
I appreciate your help on this!