简体   繁体   English

计算SSRS的变化率

[英]Calculate the rate of change in SSRS

I need to calculate the rate of change in drug usage between two dates using SSRS. 我需要使用SSRS计算两个日期之间的药物使用变化率。 I am used to using SQL, therefore I am having a difficult time with SSRS. 我习惯于使用SQL,因此在使用SSRS时遇到了困难。

I have the following information: 我有以下信息:

                             Avg_Alcohol_Use_Month   Avg_Drug_Use_Month 
First_interview_Date              1.63%                    1.34%
      1/30/2017

Followup_interview_date           2.58%                     .80%
      6/30/2017

How do I create a report that reflects the rate of change in drug usage between two dates? 如何创建一个反映两个日期之间药物使用变化率的报告? I need to create the report in SSRS but, I don't know how to write a query in SSRS that will reflect the rate of change. 我需要在SSRS中创建报告,但是,我不知道如何在SSRS中编写反映变化率的查询。

I cannot create the query in SQL because I only have access to the data through SSRS. 我无法在SQL中创建查询,因为我只能通过SSRS访问数据。

(This example is for SQL Server) (此示例适用于SQL Server)

You can do it in SQL if you save the initial results in a table or a temp data structure. 如果将初始结果保存在表或临时数据结构中,则可以在SQL中进行。 If you subquery, you can subtract the line's rates by the previous line's rate. 如果您进行子查询,则可以用前一行的费率减去行的费率。 This is by date, so you chose the MAX(date) for the given patient/doctor, whatever that (Primary Key?) is. 这是按日期排列的,因此无论(主键是什么),您都为给定的患者/医生选择了MAX(日期)。 In this case I have used "PatientID" to identify the patient. 在这种情况下,我使用了“ PatientID”来识别患者。 See below: 见下文:

--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

Use such a query as the dataset for SSRS. 使用此类查询作为SSRS的数据集。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM