0

How do I spit out records, to show up in the workbook queries pane as error records pls?

For example, if the [AcctClass] <> [_checkAcctClass] columns do not match, reject that record as an error

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

1 Answer 1

1

Composing Table.TransformRows to create errors and then putting them back in a table with Table.FromRecords might do what you want?

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

If the first row is an error then Table.FromRecords will completely break, but you can work around that by telling it what table type to expect.

Example mashup:

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.