I have a report in SSRS that shows various tablixes based on a date parameter. The user will select a date and the report will populate based on that date. This works fine. However, I would also like the user to be able to click on a "next record" button (and a "previous record" button) and the parameter (and report) will change based on the next date in the database.
The way I would normally accomplish this is by creating a text box with an action. For example, I would create a text box "Next Record", go into text box properties > Action > Go to report >, and send a new parameter that normally would be something like Parameters!survey_id.Value + 1
. This works well if I want to increment the numeric ID by a static number (ie, increment by 1). I assume it works for dates too if I want to increment the day by 1 day; but how do I do this if the next record is not one day?
One way I thought would work is to create a row_number field in the dataset that provides the values to the parameter. Here is the code:
select distinct sm.survey_date
,row_number() Over (order by survey_date) as increment
from survey_main as sm
group by sm.survey_date --sometimes there are multiple surveys in one day
order by sm.survey_date desc
which gives the results
survey_date increment
2019-09-16 194
2019-08-24 193
2019-01-14 192
My thought was I could use the increment field in the text box action to find the next survey_date, but I cannot figure out the code (or if it's possible).
Is there a way to make that work? Are there any other suggestions or workaround that you can think of?
Thank you!