0

如何吐出记录,以在工作簿查询窗格中显示为错误记录?

例如,如果 [AcctClass] <> [_checkAcctClass] 列不匹配,则将该记录作为错误拒绝

let 
    source = AccountIDsWithDuplicates,
    grouped = Table.Group(source, {"AcctID"}, {{"AcctClass", each List.Max([AcctClass]), type logical}, {"_checkAcctClass", each List.Min([AcctClass]), type logical}, {"Sum_Bal", each List.Sum([#"Bal_EUR"]), type number}}),
    // Make sure accounts only have one AcctClass 
    ErrorRecords = Table.SelectRows(grouped,  each([AcctClass] <> [_checkAcctClass])
in
    grouped
4

1 回答 1

1

编写Table.TransformRows以创建错误,然后将它们放回表中Table.FromRecords可能会做你想要的?

= Table.FromRecords(Table.TransformRows(grouped, each if [AcctClass] <> [_checkAcctClass] then error "didn't match" else _), Value.Type(grouped))

如果第一行是一个错误,那么Table.FromRecords将完全中断,但您可以通过告诉它预期的表类型来解决这个问题。

混搭示例:

let
    Source = Csv.Document("AcctID,AcctClass
        1,false
        1,true
        2,true
        2,true"),
    #"Promoted Headers" = Table.PromoteHeaders(Source),
    AccountIDsWithDuplicates = Table.TransformColumnTypes(#"Promoted Headers",{{"AcctID", Int64.Type}, {"AcctClass", type logical}}),
    grouped = Table.Group(AccountIDsWithDuplicates, {"AcctID"}, {{"AcctClass", each List.Max([AcctClass]), type logical}, {"_checkAcctClass", each List.Min([AcctClass]), type logical}}),
    ErrorRecords = Table.FromRecords(Table.TransformRows(grouped,  each if [AcctClass] <> [_checkAcctClass] then error "didn't match" else _), Value.Type(grouped))
in
    ErrorRecords
于 2015-07-02T08:44:44.223 回答