我知道如何在 SQL 中处理此问题,但我被要求在 Excel Power Query/Power Pivot 中执行此操作,而我对此不太熟悉。我的医疗数据看起来像这样:
医生 | 病人 | 符合宫颈筛查资格 | 接受子宫颈检查 | 符合结直肠筛查资格 | 接受结直肠检查 |
---|---|---|---|---|---|
医生1 | 拍1 | 是的 | 是的 | 是的 | 是的 |
医生1 | 拍2 | 是的 | 是的 | 是的 | 没有 |
医生1 | 拍3 | 是的 | 没有 | 是的 | 是的 |
医生1 | 拍4 | 没有 | 没有 | 是的 | 是的 |
医生1 | 帕特5 | 没有 | 没有 | 是的 | 没有 |
医生1 | 拍6 | 没有 | 没有 | 没有 | 没有 |
我们还知道,宫颈筛查的目标是至少 70%,结直肠筛查的目标是至少 79%。该百分比是已完成的数量与符合条件的数量之比。
在 Excel 中,我们已经能够创建一个数据透视表,如下所示:
医生 | 测量 | 符合资格 | 已演出 | 目标 | # 需要实现目标 |
---|---|---|---|---|---|
医生1 | 颈椎 | 3 | 2 | 70% | 1 |
医生1 | 结直肠 | 5 | 3 | 79% | 1 |
医生 1 总计 | 8 | 5 | 0 |
“目标所需数量”衡量标准的公式为
=ROUND(IF((MIN([Goal])/100 * [Sum of Eligible]) - [Sum of Received]<= 0, 0, (MIN([Goal])/100 * [Sum of Eligible]) - [Sum of Received]),0)
。问题是右下栏#Needed to Goal 下的医生总数。他们希望它是 2,就像宫颈线和结肠直肠线的 #Needed to Goal 之和一样。我不知道如何在小计行中对该度量进行求和。我在谷歌中找不到答案,但我可能没有搜索到正确的术语。有人能指出我正确的方向吗?
有多种方法可以实现,我个人会在 Power Query 中使用以下步骤来实现:
Screening
列Screening Type
Measure
列上透视数据Doctor
和Type
分组,计算治疗次数Goal
百分比Needed to goal number
您只需打开 Power Query 并记录您的步骤即可完成所有操作,它将类似于以下代码(您自己的步骤可能会略有不同,具体取决于您的操作方式):
let
Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Doctor", type text}, {"Patient", type text}, {"Eligible for cervical screening", type text}, {"Received cervical screening#(tab)", type text}, {"Eligible for colorectal screening", type text}, {"Received colorectal screening", type text}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Doctor", "Patient"}, "Attribute", "Value"),
#"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Columns", "Attribute", Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.Csv, false), {"Attribute.1", "Attribute.2"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Attribute.1", type text}, {"Attribute.2", type text}}),
#"Replaced Value" = Table.ReplaceValue(#"Changed Type1","for ","",Replacer.ReplaceText,{"Attribute.2"}),
#"Capitalized Each Word" = Table.TransformColumns(#"Replaced Value",{{"Attribute.2", Text.Proper, type text}}),
#"Renamed Columns" = Table.RenameColumns(#"Capitalized Each Word",{{"Attribute.1", "Measure"}, {"Attribute.2", "Type"}}),
#"Trimmed Text" = Table.TransformColumns(#"Renamed Columns",{{"Type", Text.Trim, type text}}),
#"Cleaned Text" = Table.TransformColumns(#"Trimmed Text",{{"Type", Text.Clean, type text}}),
#"Sorted Rows" = Table.Sort(#"Cleaned Text",{{"Type", Order.Ascending}}),
#"Replaced Value1" = Table.ReplaceValue(#"Sorted Rows","No","0",Replacer.ReplaceText,{"Value"}),
#"Replaced Value2" = Table.ReplaceValue(#"Replaced Value1","Yes","1",Replacer.ReplaceText,{"Value"}),
#"Changed Type2" = Table.TransformColumnTypes(#"Replaced Value2",{{"Value", Int64.Type}}),
#"Pivoted Column" = Table.Pivot(#"Changed Type2", List.Distinct(#"Changed Type2"[Measure]), "Measure", "Value", List.Sum),
#"Grouped Rows" = Table.Group(#"Pivoted Column", {"Doctor", "Type"}, {{"Eligible", each List.Sum([Eligible]), type nullable number}, {"Received", each List.Sum([Received]), type nullable number}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Goal", each if [Type] = "Cervical Screening" then 0.7
else if [Type] = "Colorectal Screening" then .79
else 0),
#"Changed Type3" = Table.TransformColumnTypes(#"Added Custom",{{"Goal", Percentage.Type}}),
#"Added Custom1" = Table.AddColumn(#"Changed Type3", "Needed to goal", each Number.RoundUp(List.Max({([Goal] * [Eligible]) - [Received], 0})))
in
#"Added Custom1"