Ok so I can do this in crystal reports but my users can not view live data which is a problem so I want to move the report to ssrs.
What I have is pretty simple. It's a report that lists businesses and number of clients. I need two groups one that has a specific business name like "Business1*" and the second group has businesses with an identifier at the end like "*[1234]".
The rest of the business can all be in one group and each group needs a total at the end. My issue is with creating this custom groupings.
If you are doing this in SQL then you can have a calculated field in your SQL statement to impose a sort order:
SELECT CASE WHEN BusinessName LIKE 'Business1%' THEN 1 WHEN BusinessName LIKE '%[1234]' THEN 2 ELSE 3 END AS SortOrder, *
FROM MyTable
ORDER BY SortOrder
Related
My tablix has following columns
Country, City, College, totalstudent,passedstudent,failedstudent
I have a parameter "GroupBy" with values "country/city/college". So, when i select one of the parameter, my tablix should be grouped by that parameter and only so that parameter column + total,passed,failed columns
For eg. If user selects GroupBy = "City" then, the tablix will show
City, totalstudent, passedstudent, failedstudent
The values in total, passed and failed is total sum grouped in that city.
The similar logic should be applied to country and college also.
So, far i am able to show the all columns with grouping applied by country, then city and then college. (which is one of simple ssrs grouping)
(My need is to only apply the one grouping based on parameter and only show that particular columns)
Note: I have a raw dataset that has all these values retrieved using inline sql from my sql database.
(Dataset1: Country,City,College,totalstudent,passedstudent,failedstudent)
You can group your table by an expression. In your group properties you would write something like this:
=Switch(Parameters!GroupBy.Value = "City", Fields!City.Value
, Parameters!GroupBy.Value = "College", Fields!College.Value
, ...)
The other columns should be able to just use regular Sum functions and work with any grouping.
I tried the different approaches (I went through the last/3rd approach)
Used multiple tablix for the different grouping conditions and used the parameter to hide/show the correct tablix in the report
Pitfall: It is awfully slow since I have 4 different grouping conditions and putting in 4 different tablix.
Using the dynamic grouping concept as illustrated at ( http://www.advancedssrs.com/2014/01/how-can-i-use-dynamic-grouping.html) which is good. But It was not suitable for my situation as it was also comparatively slow while i try to sort the columns in SSRS. (I need the sorting feature in all columns)
Created a new parameter (groupby) which is used to mimic the scenario of tabs. So, when the user selects one of the value ( Country/City/College), I am grouping my SQL result based on this groupby parameter value using conditional grouping statements and returning result back to SSRS.
SELECT
CASE WHEN #GroupBy = 'Country' THEN CountryName
WHEN #GroupBy = 'City' THEN CityName
WHEN #GroupBy = 'College' THEN CollegeName
END AS GroupTitle,
SUM(totals) AS totalstudent,
SUM(passes) AS passedstudent,
SUM(fails) AS failedstudent,
FROM #temp
GROUP BY CASE WHEN #GroupBy = 'Country' THEN CountryName
WHEN #GroupBy = 'City' THEN CityName
WHEN #GroupBy = 'College' THEN CollegeName
END
ORDER BY 1
DROP TABLE #temp
Now, I use the GroupTitle in my first column and rest of the aggregated values in the remaining columns in a single tablix.
The output looks like:
When creating your dataset, don't directly write your query in the box --- instead, use expression.
="SELECT " + Parameters!GroupBy.Value + ", passedstudent, failedstudent
FROM Table GROUP BY " + Parameters!GroupBy.Value
Your "passedstudent" and "failedstudent" will be some aggregation, either COUNT or SUM, depends on your case.
I have a requirement to report the number of people who have more than one record in the dataset for my SSRS report and I can't quite get how to filter on the grouping.
So if the dataset results are:
ID PersonID FileID
1 1234 abc
2 7890 ade
3 5647 aer
4 1234 xyz
I would like to report 1. There is one person who has more than 1 record.
Is there an expression or something I can use to do this?
Thank you.
You can use LookupSet and CountDistinct function to get the required count, however you will need the textbox used to show the calculation be in a scope.
If you want to show the number of persons with more than one record as a total in your table use this expression:
=CountDistinct(
IIF(
LookupSet(
Fields!PersonID.Value,Fields!PersonID.Value,
Fields!ID.Value,"DataSetName"
).Length>1,Fields!PersonID.Value,Nothing)
)
Set it outside any group scope:
However if you want to show the number of persons with more than one record outside your tablix in a textbox, you can add an additional tablix and delete the necessary rows and columns to leave only one textbox then set the dataset property to the dataset name you are using and use the same expression.
It should produce:
Note my dataset has more rows to ilustrate the functionality. In the right side there is only one textbox with the count.
Let me know if this helps.
If you want the result to be something like shown below.
Steps:
Create a group on Person ID
Right Click on Group > Add Total > Before
Add a column and put =Count(Fields!PersonID.Value)
If you want to display only Persons having more than one, set the visibility property of the tablix row.
I'm having an issue creating some grouping in SSRS. I can't use SQL.
Basically I have a set of data I want to turn into a pivot or summary table. I can SUM revenue by ownerID no problem, but they have some teaming and filters on their report I can't replicate. This is the basic table:
Employee Quote Revenue
User1 SUM by ownerID
User2 SUM by ownerID
User3 SUM by ownerID
User4 SUM by ownerID
User5 SUM by ownerID
User 6 SUM by ownerID
This is what they would like to measure
Teaming/Filter Quote Revenue
User 1 & User 2 SUM by Group
User 3 & User 4 SUM by Group
User 5 where customer type=1 SUM by Filter
User 5 where customer type=2 SUM by Filter
User 6 SUM by Owner ID
I've used SUM by a group name and I've tried SUM IIF but they either don't work or I get the revenue on separate rows. Would appreciate any advice.
Thank you.
My approach here would be to use a one row Tablix for each measure. That way, you can set the filter, and grouping for each scenario in its own Tablix, instead of attempting to do this in one. This keeps with the no SQL restriction. As far as display on the report, you can align each Tablix, and hide the headers, so it looks like one table in the end.
It’s not the most elegant solution in the world, but it should work.
More detail for one of the measures (User 1 and User 2 revenue):
Add a Tablix to the report
In the Tablix properties, set the dataset name to proper dataset
In the Filters properties for the Tablix, set the filter to what is need for the specific measure. You will have to use the In operator for the measures where you are teaming more than one user. In this case it will be something like “User1”, “User2” for the Value of a filter where the Expression is UserID, and the Operator is In. SSRS will change what the Value looks like in the designer, so you may have to play around with it duplicating quotes
In the Row Groups pane, for the (Details) row group, change the Group Properties group expression to use a field in the dataset that each row in the filter shares. Maybe a date, or a quote number in this case. You are not going to display this value so what it is is not important, just as long as it is the same for each row in the data you are filtering on.
In the first column of the Tablix, set the detail value to a string describing what you are showing, “User 1 and User 2”, in this instance.
In the second column of the Tablix, make the expression the sum of the revenue.
=Sum(Fields!revenue.Value)
Hide the header row
Run the report
I know this is a lot, but once you do one, you can copy and paste the Tablix, and adjust to new copy for the next measure. Hopefully, you don’t have a ton of measures! If you do, then a really need to think about doing this with SQL.
I have an SSRS Report, in the database there is a column by name Total_running_hours.
There are more than one record for a single Cycle_number like more than 1 row with same Cycle_number but different Block_numbers and the value in Total_running_hours field will be same for all the rows with same Cycle_number. Eg. 1 Cycle number with 4 diff block_numbers contain same Total_running_hours for all 4 rows.
Now the problem is, in the group footer if I put this field then it will show the Total_running_hours value only once which is correct, but my final requirement is,
I need to get the sum of this field in the Report footer which need to display the sum group wise. No matter how many rows are there for a single Cycle_number it has to take only once and display the result.
I tried in different ways like
=sum(ReportItems!textbox204.Value) // name of text box in Group footer
Error: Report item expressions can only refer to other report items
within the same grouping scope or a containing grouping scope.
=sum(Fields!total_running_hours.Value,Group_name)
Error: The scope parameter must be set to a string constant that is
equal to either the name of a containing group, the name of a
containing data region, or the name of a data set.
Can any one please help me in getting the sum Group wise
Thank you in advance.
I found solution for this Problem.
We cannot simply sum the Total_Running_hours value as this would give us duplicates and the incorrect answer. We cannot sum the reporting services group as it goes out of scope
There is no SUM DISTINCT available in Reporting Services 2005 so we can't get the distinct value that way.
Since the query may not return a particular Cycle_Number Type we cannot use that as a filter.
The solution found was to add a column of the row number within a windowed set partitioned by the Cycle_Number like this
ROW_NUMBER() OVER (PARTITION BY Cycle_Number ORDER BY Cycle_Number ) AS 'RowNumber'
Then in the reports’ footer total column we put an expression that only takes the first row’s value to sum and converts all other rows to zero in that windowed set.
=SUM(IIF(Fields!RowNumber.Value=1,Fields!Total_Running_hours.Value,0))
After using this if u found any error in textbox like #Error
Then try this
=SUM(IIF(Fields!RowNumber.Value=1,CDbl(Fields!Total_Running_hours.Value),CDbl(0.0)))
I am trying to build an access report based on data from multiple different tables within the database.
I have 3 columns which perform calculations, and I am wondering how to put this query together. All 3 columns deal with dates, but calculate them differently.
The first column retrieves the most recent date of action for a userid if the type of action is "B":
select pid, Max(date) as most_recent
from actions
where ref = 'B'
group by pid;
The second column performs a calculation based on 2 fields, one is a date and one is a number in months. I am unsure how to add these two fields so that the number is added to the date as a number of months.
what i have so far is:
select nummonths,Max(lastvisit) from users
the third column I need to select the first date thats in the future for each user (next appointment date), there will be dates before and after this date so its a little difficult:
select uid,date from visits
The code for the last 2 queries needs to be slightly modified, and I was wondering what the best approach would be to join these all together? A type of join?
If you need to build a report with data from the 3 queries, you will need related data to join them. In that case, please send the structure of the tables.
If you need to show 3 lists in one report, you can use subreports: create a new empty report. In design mode, you can add 3 subreports from the toolbox bar. To each of the subreport assign the record source property to the corresponding sql.
regards
I am unsure how to add these two fields so that the number is added to the date as a number of months.
Use the DateAdd() function:
SELECT DateAdd("m", 2, LastVisit) FROM ...
Results in a date two months from the LastVisit date.