SSRS计算矩阵中列组中所需列的百分比

时间:2017-11-09 12:02:12

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

SELECT        PatchPhase.PhaseName, MAX(PatchPhase.Sequence) AS seq, 
PatchState.Application, PatchState.Objectname, PatchState.Jobname, 
PatchState.Streamname, COUNT(*) AS Total,
PatchState.Jobdescription, 
PatchState.Status, PatchState.Timestamp      
FROM  PatchState 
INNER JOIN PatchPhase ON PatchState.Phase = PatchPhase.PhaseTech
WHERE        (PatchPhase.PhaseName IN (@Phase)) 
AND (PatchState.Application IN (@Application)) AND (PatchState.Timestamp >= @StartDate) 
AND (PatchState.Timestamp <= @EndDate)
GROUP BY PatchPhase.PhaseName, PatchState.Application, PatchState.Objectname, 
PatchState.Jobname, PatchState.Streamname, PatchState.Jobdescription, PatchState.Status, 
PatchState.Timestamp
ORDER BY PatchState.Application

我正在处理矩阵,我的列状态列包含3列(计划,运行,完成)。我想总计计+完成并除以总列。

总列位于列组之外。

calculate total %

我确实找到了一些答案,但我没有得到如何在我的代码中使用 有人可以帮忙吗?

2 个答案:

答案 0 :(得分:0)

您可以从表达式=Reportitems!Textbox133.Value

的文本框中显示一个值

而不是上面表达式中的textbox133,您必须提供您想要值的文本框的文本框名称。在您的情况下,总列

答案 1 :(得分:0)

尝试使用它进行聚合,然后使用表而不是矩阵。您现在不需要列组。由于我无法运行sql,我不能保证它是完美的,但如果没有,也许你可以稍微玩一下。它应该提供一个指南,如果没有别的。

SELECT       
PatchPhase.PhaseName, 
MAX(PatchPhase.Sequence) AS seq, 
PatchState.Application, 
PatchState.Objectname, 
PatchState.Jobname, 
PatchState.Streamname, 
PatchState.Jobdescription, 
SUM(case when PatchState.Status = 'Planned' then 1 else 0 end) as 'Planned', 
SUM(case when PatchState.Status = 'Running' then 1 else 0 end) as 'Running', 
SUM(case when PatchState.Status = 'Completed' then 1 else 0 end) as 'Completed',
(SUM(case when PatchState.Status = 'Planned' then 1 else 0 end) + SUM(case when PatchState.Status = 'Running' then 1 else 0 end)) / 
    (SUM(case when PatchState.Status = 'Planned' then 1 else 0 end) + SUM(case when PatchState.Status = 'Running' then 1 else 0 end) + SUM(case when PatchState.Status = 'Completed' then 1 else 0 end)) as totalPercentage
PatchState.Timestamp

FROM
    PatchState 
    INNER JOIN PatchPhase 
    ON PatchState.Phase = PatchPhase.PhaseTech

WHERE        
(PatchPhase.PhaseName IN (@Phase)) 
AND (PatchState.Application IN (@Application)) 
AND (PatchState.Timestamp >= @StartDate) 
AND (PatchState.Timestamp <= @EndDate)

GROUP BY 
    PatchPhase.PhaseName, 
    PatchState.Application, 
    PatchState.Objectname, 
    PatchState.Jobname, 
    PatchState.Streamname, 
    PatchState.Jobdescription, 
    PatchState.Status, 
    PatchState.Timestamp

ORDER BY 
    PatchState.Application