Powerbi 电源查询:聚合加计算
我在一份PowerBi报告中工作,试图用Power Query预处理数据。我无法解决这个问题:我试图通过在计算值时根据标准(具有相同ID的行)对行进行分组来过滤表并通过覆盖同一列(或在新列中添加该值)进行记录。我为我的英语道歉。 简言之: 我得到的是:Powerbi 电源查询:聚合加计算,powerbi,powerquery,Powerbi,Powerquery,我在一份PowerBi报告中工作,试图用Power Query预处理数据。我无法解决这个问题:我试图通过在计算值时根据标准(具有相同ID的行)对行进行分组来过滤表并通过覆盖同一列(或在新列中添加该值)进行记录。我为我的英语道歉。 简言之: 我得到的是: ID Feature1 Feature2 AB100 fs789s 10.3 AB101 j35325 5.1 AB
ID Feature1 Feature2
AB100 fs789s 10.3
AB101 j35325 5.1
AB102 jlkh234 24.4
AB102 df87 10.4
AB305 sfd 6.6
BD200 gfgs233 5.0
BD200 kj3244 4.9
BD301 sdg33 3.1
我想要的是(1):
或(二):
我一直在寻找两种解决方案,但都没有成功:
一) 电源查询编辑器中的过滤器
我尝试在Power Query Editor中应用分组行步骤:
= Table.Group(#"Filtered Rows", {"ID"}, {{"NewFeature", each List.Sum([Feature2]), type nullable number}})
但这会删除我想要保留的其余列。
我对Table.AddColumn执行了一些变通方法,但没有成功
二) 通过DAX表达式获得的新表
Table = GROUPBY(OriginalTable,OriginalTable[ID],"New Column",SUMX(CURRENTGROUP(),OriginalTable[Feature2]))
但它不起作用:其余的列和应用的过滤器都丢失了
有什么建议吗?提前谢谢 只要从您开始的地方开始,在筛选行之后进行分组,就可以做到这一点:
#"Grouped Rows" = Table.Group(#"Filtered Rows", {"ID"}, {{"Feature2", each List.Sum([Feature2]), type nullable number}, {"AllData", each _, type table [ID=nullable text, Feature1=nullable text, Feature2=nullable number]}}),
#"Expanded AllData" = Table.ExpandTableColumn(#"Grouped Rows", "AllData", {"Feature1"}, {"Feature1"}),
#"Reordered Columns" = Table.ReorderColumns(#"Expanded AllData",{"ID", "Feature1", "Feature2"})
我所做的就是这样设置分组:
这给了我这个:
然后我展开AllData列,只选择Feature1,而不使用原始列名作为前缀:
这给了我这个:
然后我将Feature1列拖到Feature2列的左侧,以获得以下结果:
如何选择要保留的
功能1
?在IDAB102
的情况下,您选择的是jlkh234
而不是df87
ID AB102的30.8是多少?您好@Angelo我正在按功能进行聚合2。谢谢你的回答。@mk:我错了,应该是bbe 34.8。谢谢,谢谢@Marc!!你的答案很完整,我想这可以解决我的问题。。我将绕过你的努力。
Table = GROUPBY(OriginalTable,OriginalTable[ID],"New Column",SUMX(CURRENTGROUP(),OriginalTable[Feature2]))
#"Grouped Rows" = Table.Group(#"Filtered Rows", {"ID"}, {{"Feature2", each List.Sum([Feature2]), type nullable number}, {"AllData", each _, type table [ID=nullable text, Feature1=nullable text, Feature2=nullable number]}}),
#"Expanded AllData" = Table.ExpandTableColumn(#"Grouped Rows", "AllData", {"Feature1"}, {"Feature1"}),
#"Reordered Columns" = Table.ReorderColumns(#"Expanded AllData",{"ID", "Feature1", "Feature2"})