(この例では、SQL Serverのためのものです)
あなたがテーブル内の最初の結果や一時データ構造を保存する場合は、SQLでそれを行うことができます。サブクエリすると、前のラインのレートでラインのレートを引くことができます。これは日付ですので、指定された患者/医師のMAX(日付)を選択しました。この場合、患者を識別するために「PatientID」を使用しました。以下を参照してください。
--Assume your values are saved in a table or other temp table
DECLARE @tmp TABLE (PatientID int, Interview_Date date, Avg_Alcohol_Use_Month decimal (4,2), Avg_Drug_Use_Month decimal (4,2))
INSERT INTO @tmp
VALUES
(1, '2017-01-30', 1.63, 1.34)
,(2, '2017-06-30', 2.58, 0.80)
,(1, '2017-03-01', 1.54, 1.23)
,(1, '2017-07-02', 3.21, 0.20)
,(2, '2017-08-23', 2.10, 4.52)
SELECT PatientID
,Interview_Date
,Avg_Alcohol_Use_Month
,Avg_Drug_Use_Month
,Avg_Alcohol_Use_Month
-
(SELECT Avg_Alcohol_Use_Month
FROM @tmp T2
WHERE T2.PatientID = T1.PatientID
AND T2.Interview_Date = (SELECT MAX(Interview_Date)
FROM @tmp T3
WHERE T3.Interview_Date < T1.Interview_Date
AND T3.PatientID = T1.PatientID
-- or whatever PK that makes the row unique for the patient.
)
) AS [Alcohol Use Rate change]
,Avg_Drug_Use_Month
-
(SELECT Avg_Drug_Use_Month
FROM @tmp T2
WHERE T2.PatientID = T1.PatientID
AND T2.Interview_Date = (SELECT MAX(Interview_Date)
FROM @tmp T3
WHERE T3.Interview_Date < T1.Interview_Date
AND T3.PatientID = T1.PatientID
-- or whatever PK makes the row unique for the patient.
)
) AS [Drug Use Rate change]
FROM @tmp T1
ORDER BY PatientID, Interview_Date
このようなクエリをSSRSのデータセットとして使用します。
質問を明確にすることはできますか?あなたが何を望んでいるのか分かりません。 (式のヘルプ、計算フィールド、データセット) –
SQLを使用する方が快適な場合は、単純なデータセットとしてデータセット内で作業するほうが簡単でしょう。 SSRS式は、データセットによって提供されるデータ(通常はSQL Serverのクエリまたはストアドプロシージャから取得されるデータ)で動作します。 –