Solved

Custom Sorting in SSRS

Posted on 2011-02-13
5
2,186 Views
Last Modified: 2012-05-11
I have a dimension with these attribuyes:
Age Age Range
12    1-12
18     13-19
21     20-30
34      >30

I need to sort sort the Age Range field in a in SSRS Tablix in Descending order of >30, 20-30, 13-19, 1-12. The default sorting of z-A in SSRS was not doing so I wrote this expression below is not sorting the age range properly as well:
IIF(SortField.Age Range = >30, SortDirection.Value = 4
ISortField.Age Range = 20-30, SortDirection.Value = 3,
ISortField.Age Range = >13-19 SortDirection.Value = 2,
SortField.Age Range = 1-12, SortDirection.Value = 1)

Does anyone have the idea of expression that could sort the age in order of >30, 20-30, 12-19 and 1-12.

0
Comment
Question by:Projack
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 13

Expert Comment

by:devlab2012
ID: 34888580
Instead of sorting on AgeRange field, add a new calculated field in the dataset say CalAgeRange with following expression:

=Switch(
Fields!AgeRange.Value = ">30", "1",
Fields!AgeRange.Value = "20-30", "2",
Fields!AgeRange.Value = "12-19", "3",
Fields!AgeRange.Value = "1-12", "4"
)


Now do sorting on CalAgeRange field instead of AgeRange.
0
 
LVL 40

Expert Comment

by:lcohan
ID: 34888674
I would use a CASE statement instead in the SELECT statement providing data for your report and order by that column(number) DESC like:

SELECT id,
      CASE
            WHEN SortField_Age >=30                                    THEN 4
            WHEN SortField_Age >20  AND SortField_Age <30      THEN 3
            WHEN SortField_Age >=13 AND SortField_Age <19      THEN 2  
            WHEN SortField_Age >=1  AND SortField_Age <12      THEN 1 ELSE 0 END as SortOrder,
            name
FROM
      clients
ORDER BY 2 DESC-- SortOrder
0
 

Author Comment

by:Projack
ID: 34889649


devlab2012:
It throw invalid field exppression for age_sort calculated field.
0
 

Author Comment

by:Projack
ID: 34889664
lcohan:
1 the age-range is in format >30, 20-30,12-19, 1-12
2. How can I implement this solution in SSRS expression
0
 
LVL 40

Accepted Solution

by:
lcohan earned 500 total points
ID: 34889788
if the age-range is a column in your query that provides data for your report then you could replace that query data with the CASE statement like below:
SELECT
....
      CASE
            WHEN [age-range] = '>30'    THEN 4
            WHEN [age-range] = '20-30'  THEN 3
            WHEN [age-range] = '13-19'  THEN 2  
            WHEN [age-range] = '1-12'   THEN 1 ELSE 0 END as SortOrder,
....
FROM your_table_name
ORDER BY 2 DESC-- 2 is the number of SortOrder column in the SELECT list

Hope this helps...
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hi All, I am here to write a simple article to move SSRS (SQL Server Reporting Services) reports from one server to another. When I have faced the same issue to move reports those were developed by developer on development server and now need to …
Introduction In the following article I’ll be discussing and demonstrating several different ways of how images can be put on a report. I’m using SQL Server Reporting Services 2008 R2 CTP, more precisely version 10.50.1352.12, but the methods ex…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question