POWER BI:如何使用另一个 table 和因子来缩放多类别/多个值

POWERBI: how to scale a multi-categories / multiple vales using another table with factors

我需要一些帮助:

我想使用第二个 table 的因子对第一个 table 进行缩放以获得第三个 table:

前table中的索引是重复的(你可以把它们当作类别)。

如何仅使用 POWER BI Desktop 的 Power Query 编辑器获得第三个 table?

这是pbi

谢谢!

(您的示例数据有误,要缩放的值的索引与缩放的索引不匹配 Table,但无论如何)

Powerquery 方法使用 unpivot、merge 然后 pivot。这是 Values to Scale 数据的代码,使用来自 的数据将其转换为 Scaled Table因素 查询

let Source = Excel.CurrentWorkbook(){[Name="ValuestoScaleData"]}[Content],

// assumes presence of query FACTORS that contains data as shown
FactorTable1 = Table.UnpivotOtherColumns(FACTORS, {"INDEX"}, "Attribute", "Value"),
FactorTable2 = Table.ReplaceValue(FactorTable1,"FACTOR ","",Replacer.ReplaceText,{"Attribute"}),

#"Added Index" = Table.AddIndexColumn(Source, "Index.1", 0, 1, Int64.Type),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Added Index", {"INDEX", "Index.1"}, "Attribute", "Value"),
#"Replaced Value" = Table.ReplaceValue(#"Unpivoted Other Columns","VALUE ","",Replacer.ReplaceText,{"Attribute"}),
#"Merged Queries" = Table.NestedJoin(#"Replaced Value", {"INDEX", "Attribute"}, FactorTable2, {"INDEX", "Attribute"}, "Table1", JoinKind.LeftOuter),
#"Expanded Table2" = Table.ExpandTableColumn(#"Merged Queries", "Table1", {"Value"}, {"Value.1"}),
#"Added Custom" = Table.AddColumn(#"Expanded Table2", "MULT", each [Value]*[Value.1]),
Rename = Table.TransformColumns(#"Added Custom",{{"Attribute", each "Scaled "&_, type text}}),
#"Removed Columns" = Table.RemoveColumns(Rename,{"Value", "Value.1"}),
#"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Attribute]), "Attribute", "MULT", List.Sum),
#"Sorted Rows" = Table.Sort(#"Pivoted Column",{{"Index.1", Order.Ascending}}),
#"Removed Columns1" = Table.RemoveColumns(#"Sorted Rows",{"Index.1"})
in  #"Removed Columns1"