Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Custom Sorting in SSRS

Posted on 2011-02-13
5
Medium Priority
?
2,348 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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

After much searching across the internet I have found that you could not set the name of the file you were attaching to dynamic report subscriptons in Microsoft Reporting Services. I did manage to find one article showing you how your could make a s…
This code started out as a fix for a customer that had incoming data that was hunderds of numbers and words long that was to fit in one column. The problem was that the customer did not want to split words or numbers when wrapping in the column. …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

650 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