I have a report in SSRS which displays the revenue for each month:
| MO-YR | Revenue|
|01-2019 | $10.000|
|02-2019 | $13.000|
|03-2019 | $9.500 |
|... |... |
|... |... |
|... |... |
|10-2020 | $21.000|
|11-2020 | $850 |
I have to do the 3 months average and 12 months average, so for example: For April of 2020, the 3 months average will be [(January 2020 Revenue) + (February 2020 Revenue) + (March 2020 Revenue)] / 3. The 12 months average will be the same, but it'll have 12 months added to each other and then divided by 12. My question is: how can I somehow get values of 3 previous rows and how can I get values from 12 previous rows in SSRS?
I'm adding also the code of my dataset source, stored procedure:
SELECT
*
FROM
(SELECT
pr.company_name AS [CompanyName],
pr.sr_service_recid AS [Ticket],
pr.unit_price AS [Invoice Amount],
FORMAT(ih.Date_Invoice, 'MM-yyyy') AS [MO YR],
FORMAT(EOMONTH(ih.Date_Invoice),'dd') AS [MO Days],
ih.Date_Invoice AS [WorkDate]
FROM
Product pr
LEFT JOIN InvoiceHeader ih
ON
ih.Billing_Log_RecID = pr.Billing_Log_RecID
AND
ih.Company_RecID = pr.company_recid
LEFT JOIN SRService sr
ON
pr.sr_service_recid = sr.SR_Service_RecID
LEFT JOIN vService vs
ON
vs.SR_Service_RecID = pr.sr_service_recid
UNION ALL
SELECT
vt.company_name AS [CompanyName],
vt.SR_Service_RecID AS [Ticket],
vt.Billable_Hrs * CASE
WHEN
vt.Hourly_Rate < 25
THEN
0.00
ELSE
vt.Hourly_Rate
END [Invoice Amount],
FORMAT(vt.Date_Start, 'MM-yyyy') AS [MO YR],
FORMAT(EOMONTH(vt.Date_Start), 'dd') AS [MO Days],
vt.Date_Start AS [WorkDate]
FROM
vTime vt
LEFT JOIN SRService sr
ON
sr.SR_Service_RecID = vt.SR_Service_RecID
LEFT JOIN vService vs
ON
vs.SR_Service_RecID = vt.SR_Service_RecID
LEFT JOIN Product pr
ON
pr.sr_service_recid = vt.SR_Service_RecID
LEFT JOIN InvoiceHeader ih
ON
vt.Invoice_Number = ih.Invoice_Number
)union_all
ORDER BY [WorkDate]