question

dmedici avatar image
dmedici asked

Conditional Grouping in SSRS

Hello everyone, I've created a report that is supposed to use a tablix to group data exactly as seen below: Region | State | Customer | CustomerKey | Status North | NY | Bob | 111 | VIP | | Mary | 112 | VIP | MA | Bob | 111 | Regular | | Tim | 113 | Regular East | MD | Greg | 114 | VIP | VA | Bob | 111 | VIP West | CA | Greg | 114 | Regular | | Mary | 112 | VIP | | Sean | 115 | Regular | WA | Sean | 115 | VIP This is relatively easy because a view has been created with all the appropriate fields to make grouping in the tablix simple. The only problem I have is that, it in the database, users who have VIP status also have duplicate records of them with Regular status. For example, the data is stored as follows: Region | State | Customer | CustomerKey | Status North | NY | Bob | 111 | VIP North | NY | Bob | 111 | Regular North | NY | Mary | 112 | VIP North | NY | Mary | 112 | Regular North | MA | Bob | 111 | Regular North | MA | Tim | 113 | Regular East | MD | Greg | 114 | VIP East | MD | Greg | 114 | Regular East | VA | Bob | 111 | VIP East | VA | Bob | 111 | Regular West | CA | Greg | 114 | Regular West | CA | Mary | 112 | VIP West | CA | Mary | 112 | Regular West | CA | Sean | 115 | Regular West | WA | Sean | 115 | VIP West | WA | Sean | 115 | Regular The report is therefore displaying the data as follows: Region | State | Customer | CustomerKey | Status North | NY | Bob | 111 | VIP | | | | Regular | | Mary | 112 | VIP | | | | Regular | MA | Bob | 111 | Regular | | Tim | 113 | Regular East | MD | Greg | 114 | VIP | | | | Regular | VA | Bob | 111 | VIP | | | | Regular West | CA | Greg | 114 | Regular | | Mary | 112 | VIP | | | | Regular | | Sean | 115 | Regular | WA | Sean | 115 | VIP | | | | Regular If a user has a Status of VIP, I don't care about their record with their Status of Regular (for that particular Region/State). Is there anyway I can hide these conditionally? Thanks in advance
ssrsssrs-2008conditional
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
ThomasRushton avatar image
ThomasRushton answered
What you could do is change your SELECT Statement to include something like: SELECT Region, STate, Customer, CustomerKey, Status FROM (SELECT Region, State, Customer, CustomerKey, Status, Row_Number() OVER (PARTITION BY Region, State, Customer, CustomerKey) ORDER BY CASE WHEN CustomerKey = 'VIP' THEN 0 ELSE 1 END AS RowNum) FROM MyTableName) WHERE RowNum = 1 ORDER BY Region, State, Customer, CustomerKey Back of an envelope, might be a few kinks to work out...
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kev Riley avatar image Kev Riley ♦♦ commented ·
+1 definitely - do the heavy lifting in the query, and let SSRS do the displaying
3 Likes 3 ·
dmedici avatar image dmedici commented ·
With some tweaks, worked like a charm, thanks!
1 Like 1 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.