Hopefully, I can explain this clearly! Our report allows user to select a variable number of academic years. They can be consecutive or not. In this case, say the user selects 2017, 2015, 2013. The report presents like this:
AcYear TotCredits %Change
2013 251 0.00
2015 255 0.00
2017 1102 0.00
Because the SQL that provides the datasource is assuming the previous year is one year prior. So 2015 is being compared against 2014, even though we're not selecting that info, which is why it's 0. 2017 is being compared against 2016, even though the user selected 2015. So, either in the initial SQL or in the report table expression, how would I go about getting the credits for the most immediately prior SELECTED academic year, no matter how many were selected, and then calculating the percent change based on that??
(If the user selected consecutive years, say 2017 and 2016, the data looks like this:)
AcYear TotCredits %Change
2016 458 0.00%
2017 19 -95.85%
This is the self join to get the "previous" year:
from
cte
left join cte as prev1
on cte.academic_year - 1 = prev1.academic_year
and cte.subject = prev1.subject
Thanks for any ideas!