我希望开发一个excel模型,它将使用powerpivot /和power query从数据仓库中提取大量数据,然后根据某些规则执行一系列操作。
我已经管理了第一部分,但是,我正在努力应用这些规则。简而言之,模型应该首先检查规则1是否正确,如果不正确,那么它应该检查规则2是否正确,如果不是规则3等等。
可能有多个规则是正确的,但是,应用的操作应该基于规则的顺序。
一系列if语句可能有用,但我希望避免这种情况。
感谢任何帮助/建议。
答案 0 :(得分:0)
我相信通过使用外连接,这是一种方法。
您可以合并每个表中的变量列,然后合并(加入)这两个表,使用规则和记录表的新合并变量列作为键匹配;然后拆分新合并表中的合并变量列,最终得到这个比较结果表(比较):
以下是规则表中的M代码:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Rule #", Int64.Type}, {"Variable 1", type text}, {"Variable 2", type text}, {"Variable 3", type text}, {"Variable 4", type text}, {"Variable 5", type text}}),
#"Demoted Headers" = Table.DemoteHeaders(#"Changed Type"),
#"Merged Columns" = Table.CombineColumns(#"Demoted Headers",{"Column2", "Column3", "Column4", "Column5", "Column6"},Combiner.CombineTextByDelimiter(",", QuoteStyle.None),"Merged")
in
#"Merged Columns"
这是记录表中的M代码:
let
Source = Excel.CurrentWorkbook(){[Name="Table15"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Record", type text}, {"Variable 1", type text}, {"Variable 2", type text}, {"Variable 3", type text}, {"Variable 4", type text}, {"Variable 5", type text}}),
#"Demoted Headers" = Table.DemoteHeaders(#"Changed Type"),
#"Merged Columns" = Table.CombineColumns(#"Demoted Headers",{"Column2", "Column3", "Column4", "Column5", "Column6"},Combiner.CombineTextByDelimiter(",", QuoteStyle.None),"Merged")
in
#"Merged Columns"
这是比较表中的M代码:
let
Source = Table.NestedJoin(Records,{"Merged"},Rules,{"Merged"},"NewColumn",JoinKind.FullOuter),
#"Expanded NewColumn" = Table.ExpandTableColumn(Source, "NewColumn", {"Column1"}, {"NewColumn.Column1"}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Expanded NewColumn","Merged",Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv),{"Merged.1", "Merged.2", "Merged.3", "Merged.4", "Merged.5"}),
#"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Merged.1", type text}, {"Merged.2", type text}, {"Merged.3", type text}, {"Merged.4", type text}, {"Merged.5", type text}}),
#"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
#"Renamed Columns" = Table.RenameColumns(#"Promoted Headers",{{"Rule #", "Rule # Matched"}})
in
#"Renamed Columns"