現在、Power BI のクエリ エディターを使用して、一部のデータのピボット解除、変換、結合、再ピボット、および再結合を行っています。説明:
REF_機能:
ID#| Capability.1 | Capability.2 | Capability.3|
97 | Crawl | Walk | Run |
98 | Crawl | null | null |
99 | Crawl | Walk | null |
表 2:
Capability | Attribute| Value |
Crawl | Vehicle1 | 4 |
Walk | Vehicle1 | 3 |
Run | Vehicle1 | 2 |
Crawl | Vehicle2 | 0 |
Walk | Vehicle2 | 1 |
Run | Vehilce2 | 1 |
Crawl | Vehicle3 | 0 |
Walk | Vehicle3 | 5 |
Run | Vehicle3 | 5 |
アンピボット、フィルタリング、クエリのマージ、列の展開、再ピボットと再マージの組み合わせを使用して、次の OutputTable を取得します。
ID#| Capability.1 | Capability.2 | Capability.3| Score.Vehicle1 | Score.Vehicle2 | Score.Vehicle3 |
97 | Crawl | Walk | Run | 9 [4+3+2] | 2 [0+1+1] | 10 [0+5+5] |
98 | Crawl | null | null | 4 [4+null+null] | 0 [0+null+null] | 0 [0+null+null] |
99 | Crawl | Walk | null | 7 [4+3+null] | 1 [0+1+null] | 5 [0+5+null] |
Vehicle2CapaScore と Vechile3CapaScore の下の ID#97 の場合、それぞれ 2 と 10 のスコアではなく、両方のスコアを 0 にします。説明すると...ビークルの特定の機能の完全なスコアが0の場合、すべての機能のスコアが0になります。もっと簡単に言えば、どんなに上手に歩いたり走ったりしても、ハイハイができなければ意味がありません。
そのロジックをクエリに組み込む手助けが必要です。
let
Source = OData.Feed("SOURCE_vti_bin/listdata.svc"),
REF_Capability = Source{[ID#="REF_Capability",Signature="table"]}[Data],
#"Split Column by Delimiter" = Table.SplitColumn(Table1,"Capability",Splitter.SplitTextByDelimiter("; ", QuoteStyle.Csv),{"Capability.1", "Capability.2", "Capability.3"}),
#"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Capability.1", type text}, {"Capability.2", type text}, {"Capability.3", type text}}),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Change Type", {"ID#"}, "Attribute", "Value"),
#"Filtered Rows" = Table.SelectRows(#"Unpivoted Other Columns", each ([Attribute] = "Capability.1" or [Attribute] = "Capability.2" or [Attribute] = "Capability.3") and ([Value] <> "")),
#"Merged Queries" = Table.NestedJoin(#"Filtered Rows",{"Value"},Table2,{"Capability"},"NewColumn",JoinKind.LeftOuter),
#"Expanded NewColumn" = Table.ExpandTableColumn(#"Merged Queries", "NewColumn", {"Attribute", "Value"}, {"VehicleScore.Attribute", "VehicleScore.Value"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded NewColumn",{"Attribute", "Value"}),
#"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[VehicleScore.Attribute]), "VehicleScore.Attribute", "VehicleScore.Value", List.Sum)
in
#"Pivoted Column"
let
Source = OData.Feed("SOURCE/_vti_bin/ListData.svc"),
OutputTable = Source{[ID#="OutputTable",Signature="table"]}[Data],
#"Merged Queries" = Table.NestedJoin(#OutputTable,{"ID#"},REF_Capability,{"ID#"},"NewColumn",JoinKind.LeftOuter),
#"Expanded NewColumn" = Table.ExpandTableColumn(#"Merged Queries", "NewColumn", {"Vehicle1", "Vehicle2", "Vehicle3"}, {"Score.Vehicle1","Score.Vehicle2", "Score.Vehicle3"})
in
#"Expanded NewColumn"