I am working with SSRS2005. I have requirement to display total in the footer. We have to display the total of each category. What I used to do is, write expression for all category names and hide those totals that are not having any value in the current selection.
Mango Count = sum(iif(fields!Category.Value = “Mango”,0,1))
Apple Count = sum(iif(fields!Category.Value = “Apple”,0,1))
However, in the new requirement, I don’t have the knowledge of categories. It could be any number of categories. Is it possible to write an expression for this?
Please help
Thanks
Lijo Cheeran Joseph
Remove the footer from your table. Create a second dataset that sums by group (Select Fruit, Count(*) AS FruitCount From Fruits Group by Fruit), then add another table below your current table which uses this new dataset and displays the results.
Related
I did a lookup function in ssrs where the source is a reportItem reference. I want to return the value from the table that I am looking up based on the reportItem reference. The report is retrieving the correct values, but and I'm getting repeated rows and I'd like to know if there's a way to eliminate that. My parameters in the tablix is based on a ticket number.
The underlying data has 3 transactions but 9 rows are currently being returned.
In SSRS, my query is:
Select
ticketno, name, control, value
from ticket a
inner join details b on a.ticketno = b.ticketno
where control like 'LS%' and ticket = 'ED08'
The return result contains 4 rows transactions
ie:
Ticket
Name
Control
Value
ED08
Eng
LS1
A
ED08
Acct
LS2
B
ED08
Med
LS3
C
In SSRS, I used a table and hard coded the Name as it's possible that there will be no values.
I hard coded Eng, Acct, Med, Dent for names.
I entered an expression on each individual row with an expression
=lookup(ReportItems!textbox.Value,Fields!Name.Value,Fields!Value.Value, "UDF_Det")
However, when I run the report, I get extra rows.
The transactions retrieved from the ticket in SQL only retrieved 3 rows, so I would have expected that. Is there a way to filter on row specific data?
I have looked at this post Adding values to a Report when there is no Data in query SSRS but since I am not doing any calculations I'm not sure why I am getting repeat rows.
My design looks like this:
Output looks like this:
Acually, now I've edited your question I understand the problem. :)
You can just get a list of Name and left join from it to your existing query.
You maybe able to get the list from an existing table (hopefully) or you could hardcode one (avoid if possible).
Assuming all the Names you need are in your ticket table you could use something like this...
SELECT DISTINCT [Name] FROM ticket
(if name comes from another table, just change the query to suit)
then left join your existing query to this, something like
SELECT n.[Name], t.ticketno, t.control, t.value
FROM (SELECT DISTINCT [Name] FROM ticket) n
LEFT JOIN (
Select ticketno, name, control, value
from ticket a
inner join details b on a.ticketno = b.ticketno
where control like 'LS%' and ticket = 'ED08'
) t
ON n.[Name] = t.[Name]
which should give you something like
Name
Ticket
Control
Value
Eng
ED08
LS1
A
Acct
ED08
LS2
B
Med
ED08
LS3
C
Dent
NULL
NULL
NULL
Then you can simply have one row in the detail group in your table to output the results.
If this does not help, post some sample data from your database tables and show the full report design including row groups etc
I'm fairly new to SQL and have a question regarding a query.
I have a database with various pictures attached to a product. All these pictures have a prediction. The structure is like this:
product_ id picture_id prediction
1------------pic1.jpg----------type a
1------------pic2.jpg----------type b
1------------pic3.jpg----------type b
2------------pic4.jpg----------type a
2------------pic5.jpg----------type a
2------------pic6.jpg----------type a
3------------pic7.jpg----------type c
...
... so on.
Each pictures is predicted individually and because of that some of the products have contradictory predictions (meaning that on the same products some pictures are predicted type a while others are predcited type b).
I want to filter out all of these products with a query. In other words: I need all product_ids where the predictions for the pictures linked to it are not all the same. In our example I want it only to show me product 1.
I tried some stuff with GROUP BY, but have not yet gotten anywhere near the result that I want.
Thanks for helping,
Cheers
Use COUNT(DISTINCT prediction) to get the number of different predictions. It will be more than 1 for the products with different predictions.
SELECT product_id
FROM yourTable
GROUP BY product_id
HAVING COUNT(DISTINCT prediction) > 1
I am working with all currency types and rates in a query. Because they are the most popular, is it possible to have USD and EUR positioned at the top of a query list before displaying the rest of the currency codes in alphabetical order?
Let's say your table is called tblRate having two columns, Rate and Curr.
Create a query that uses the Switch function to assign a ranking order to USD (ranking order 1), EUR (raking order 2).
Assign ranking order 3 to all other currencies using the Nz function.
In your query you order by rank, next by currency.
SQL view:
SELECT Rate, Curr
FROM tblRate
ORDER BY Nz(Switch(Curr = "USD",1, Curr = "EUR",2),3), Curr
If you have a table providing the source data for the list, add a 'OrderNum' column to the table, then put 1 and 2 into USD and EUR, respectively. Then, in everything else, put a larger number, such as 3. If they all need to follow alphabetical order after that, make the sort command have two variables in the query that provides data to the list box or drop down. If your table containing the currency codes is called 'tblCurrencyCode', and the field containing the codes is called 'CurrencyCode', your code would look something like this:
SELECT CurrencyCode
FROM tblCurrencyCode
ORDER BY OrderNum ASC, CurrencyCode ASC
An alternate method would be:
Create a query for most used currencies from your currency table and then join the list with your currency list query.
Something like.
Select currency
from QryMostUsedCurrencies
Union all
Select currency from CurrencyTable
where currency not in (select currency from QryMostUsedCurrencies)
In this way, you can keep a list of most used currencies in a separate query. Either by dynamically looking at past transactions or simple select query from Currency Table for those items you want to appear on top.
This helps you to change your most used currencies in one place rather than having ranking sql in multiple places.
I have a query that returns Sales representatives number, Category, Sales.
The result is something like this:
There are 4 categories called G1,G2,G3,G4.
As you can see the Sales representative 11 sold 10 each category (Yellow rows).
But Representative 12 sold only for category G3 and G4.
The idea is to show in the report all the categories and populate with 0 all those who did not sell on that particular category.
It must be grouped by Sales Representative so if you make a tablix grouping by Sales Representatives you will have something like this:
But you want something like this:
Is there any expression I could use to add these?
What I did so far is to create a group, that group of course are my Sales representatives and combine the cells for that Column and created a Row group for each category, is something like this:
But if you execute that report it will repeat all categories G1,G2... For each time that category exists for that particular Sales Representative.
Another problem is, how can you evaluate The hardcoded category in your report if it does not exist in your datasource you cant make Iif("G1" = Fields!Category.Value,Fields!Sales.Value,"0") as you are not comparing G1 with Null or IsNothing, you are comparing what it exists.
I think you can achieve this smoothly using T-SQL at query level. I don't know why you don't use the simplest way to apply this kind of logic since in T-SQL you can use almost every logic.
However I like this kind of challenges so I come with this possible solution.
This is my sample dataset:
In SSRS dataset (not in T-SQL) I've added a calculated field called Another
Another field is set to the below expression:
=Fields!SalesRep.Value & "-" & Fields!Category.Value
I've added a tablix with the following data arrangement
As I mentioned before category field is hardcoded, the right column with Sales
is set to this expression:
=iif(IsNothing(lookup(Fields!SalesRep.Value & "-" & ReportItems!Textbox62.Value,
Fields!Another.Value,Fields!Sales.Value,"DataSet7")),0,
lookup(Fields!SalesRep.Value & "-" & ReportItems!Textbox62.Value,
Fields!Another.Value,Fields!Sales.Value,"DataSet7"))
Note: ReportItems!Textbox62.Value corresponds to textbox where G1
was hardcoded. You have to replace the textbox reference for the
corresponding in your tablix for every category.
It will preview the below tablix.
Let me know if this was helpful.
I have an SSRS report based on stored procedure dataset. The report shows employees and their performance rating and uses bunch of parameters to filter the data.
Now I would like to add a table below that would dynamicaly count and show occurence of given mark in the main report. The table data should update according to what is visible in the main report after filtering it.
I wanted also to add a chart that would visualize this.
It would be feasible to do if the extra table and chart could run from the same dataset as the main report. This however seems impossible as this dataset does not always contain all the possible marks. It can happen that some marks are missing (when filtered or missing at all), and I would like to show the mark with zero value (and zero value bar in the chart) instead of just skipping it.
So far I was able to produce the table by hardcoding the headers and using SUM(IIF...) expressions under each header
Here is the expression for the "C" column.
=Sum(IIf(Fields!current_performance_rating.Value = "C", 1, 0))
It shows correctly the number of "C" marks appearing in the main report.
Now I am stuck with creating a chart that would show this.
I am not able to hardcode expressions similar to the ones in the table
and can't make the chart run from the main dataset, because the categories
would be missing after filtering the report (and not showing zero).
I tried linking datasets with Lookup function, but that did not work.
Which way should I go now? What is the best practice in such case?
Thank you for any hints!
Thanks trubs.
I have right joined a view that contains
all the marks and that solves the issue
of missing categories.
The join is on something like
tb.current_performance_rating = vw.performance_rating_code
I can now add the value series that counts
the occurence of current_performance_rating
per category. This works all fine.
However there is another table joined
(on employee_id) that stores last year's rating.
This rating obviously may differ to the current one.
On the same chart I would like to add another
series that counts last year's rating per category.
The category is there already, joined to the current
rating.
So you can have row like:
curren rating | last year's rating | category
C | H | C
So I am stuck, because when SSRS groups per category
it counts last year's H rating and displays
i the C category, while it should display it in H.
Sorry I can't post any pictures, seems like I
need more reputation points.
Hope you can understand what I mean.
Regards!
You're likely better off changing your query to return results for marks where there are no values.
So instead of inner joining to your Performance Rating table, use a Right Join or Full Outer Join, so that all the data is always available.
eg: Instead of...
SELECT p.PersonId, PersonName, g.Grade
FROM Person p
INNER JOIN PersonGrades pg ON p.PersonId = pg.PersonId
INNER JOIN Grades g ON pg.GradeId = pg.GradeId
Use
SELECT p.PersonId, PersonName, g.Grade
FROM Grades g
LEFT JOIN PersonGrades pg ON pg.GradeId = g.GradeId
LEFT JOIN Person p ON p.PersonId = pg.PersonId
If that's not clear, post your query and we could help get the data in the right format.
The way to go was to simplify the dataset that the main report was based on.
Then I took the query from that dataset, used COUNT and GROUB BY to count number of occurence of each current year mark in the main report. Then I right joined (thx trubs!) with the view that contains all the possible marks (so that my extra table headers/chart categories would not disappear if they do not exist). As a result I got the number of occurence in current year per mark (table A).
Then I did almost exactly the same for the last year's rating, just used last year's mark. I got the number of occurence of last year's mark per mark (table B).
I inner joined table A and B on common column (the mark, which will always appear thanks to the RIGHT joins). This gave me a table (dataset eventualy) where I had:
mark | current year mark count | last year mark count.
Making a table and chart basing on this was really easy then.
There was some more fun of adding all the parameters from the main report to both the count queries, so that the counts would change when report is filtered. I also needed to make sure that count works not only when my filter criteria (in WHERE stetement) equal the parameter provided from the report, but also when they are NULLs (so I added OR column_i_filter_on IS NULL).
This works smoothly - the table content and chart changes when filtering changes (although runs slowly, as parameters are passed to two big dataset, one of which uses them twice).
Thanks for all the help!!
psh