SSRS 计算矩阵列组中所需列的百分比
SSRS calculate % of desired colums in column group in matrix
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 列(计划、运行、已完成)。我想将计划+完成的总和除以总列。
总列在列组之外。
我确实找到了一些答案,但我不知道应该如何在我的代码中使用
有人可以帮忙吗?
您可以从表达式 =Reportitems!Textbox133.Value
中获取显示在文本框中的值
而不是上面表达式中的 textbox133,您必须给出您想要从中获取值的文本框的文本框名称。在您的情况下,总列
尝试使用它来聚合,然后使用 table 而不是矩阵。您现在不需要列组。因为我不能 运行 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
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 列(计划、运行、已完成)。我想将计划+完成的总和除以总列。
总列在列组之外。
我确实找到了一些答案,但我不知道应该如何在我的代码中使用 有人可以帮忙吗?
您可以从表达式 =Reportitems!Textbox133.Value
而不是上面表达式中的 textbox133,您必须给出您想要从中获取值的文本框的文本框名称。在您的情况下,总列
尝试使用它来聚合,然后使用 table 而不是矩阵。您现在不需要列组。因为我不能 运行 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