【问题标题】:Calculate the rate of change in SSRS计算 SSRS 的变化率
【发布时间】:2017-10-05 18:19:12
【问题描述】:

我需要使用 SSRS 计算两个日期之间药物使用的变化率。我习惯使用 SQL,因此我在使用 SSRS 时遇到了困难。

我有以下信息:

                             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

如何创建反映两个日期之间药物使用变化率的报告?我需要在 SSRS 中创建报告,但是我不知道如何在 SSRS 中编写一个反映变化率的查询。

我无法在 SQL 中创建查询,因为我只能通过 SSRS 访问数据。

【问题讨论】:

  • 你能澄清你的问题吗?我不确定你希望得到什么。 (表达式帮助、计算字段、数据集)
  • 如果您更习惯使用 SQL,那么在数据集中完成工作可能更容易,因为这将是纯 SQL。 SSRS 表达式处理数据集提供的数据,而数据集(通常)是从查询中检索到的数据或从 SQL Server 存储的过程。

标签: reporting-services ssrs-2012 reporting-services-2012


【解决方案1】:

(此示例适用于 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 的数据集。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-14
    • 1970-01-01
    • 1970-01-01
    • 2011-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多