Rolling Years in SSRS Report

Chris Bridge 21 Reputation points
2021-03-15T23:52:16.483+00:00

I'm trying to think of the best way to accomplish this. I already asked about ranks, but then realized I really need rolling ranks.

This is what I currently have.

SELECT distinct *, (dense_rank() over (order by [Year]) - 1) / 3 + 1 as [group]  
FROM dwmy  

As you can see, it's static. It should group by 3 years. When a new year starts, the oldest year would fall off the first page (but still be visible in the report).

So, in the current year, it would look like:
78005-image.png

In 2022:
77938-image.png

In 2023:
77984-image.png

The old groupings would still be on older pages, so users could still see the old groupings of 2019, 2020, 2021 and 2020, 2021, 2022.

Does anyone know an easy way to accomplish this? Thank you.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,692 questions
SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
2,798 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,552 questions
{count} votes

2 answers

Sort by: Most helpful
  1. ZoeHui-MSFT 32,586 Reputation points
    2021-03-16T02:30:50.777+00:00

    Hi @Chris Bridge ,

    Do you mean that you want the SSRS report to be like below?

    78061-tempaa122.gif

    If yes, you could add the page break on the group.

    78071-screenshot-2021-03-16-102957.jpg

    If I misunderstand your needs, please incorrect me.

    Regards,

    Zoe


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    Hot issues October


  2. ZoeHui-MSFT 32,586 Reputation points
    2021-03-22T09:26:56.207+00:00

    Hi @Chris Bridge ,

    If you want like this, I think that you should modify the query you mentioned before to make the year to group by 2019-2021 and 2020-2022.

     declare @newyears  table ( [year] int )  
    
     insert @newyears values  
     ( 2018 ),  
     ( 2019 ),  
     ( 2020 ),  
     ( 2021 ),  
     ( 2022 )  
    
    
    
     ;with cte as (  
     select *,ROW_NUMBER() over (order by (select null)) rn from @newyears)  
     select * from (  
    select year, 1 num from cte where rn between 1 and 3  
    union  
    select year, 2 num from cte where rn between 2 and 4  
    union   
    select year, 3  num from cte where rn between 3 and 5) a  
    order by num  
    

    And then it will be like below. Hope it will give you some help.

    80173-tempaa1222.gif

    Regards,
    Zoe


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    What can I do if my transaction log is full?--- Hot issues November

    How to convert Profiler trace into a SQL Server table -- Hot issues November

    0 comments No comments