Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

An OR filter on multiple columns

Hi, i have a table that i wish to check for missing data in multiple columns, and if any of those columns are empty, return the row. I think i need to create a column and use an OR statement. Howeve...
  • Nolock's avatar
    Nolock
    7 years ago

    Hi Anonymous,

    here we go:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUUoC4mQgTgHiVCA2NtAzMNMzMjC0VIrViVZCUgFBRqjyiXAJKIqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Field A" = _t, #"Field B" = _t, #"Field C" = _t, Column4 = _t, Column5 = _t, #"Field D" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Field D", type datetime}}),
        // columns which I want to test as a list
        ColumnsNamesForNullTest = {"Field A", "Field B", "Field C"},
        // select only rows which contains at least one value which is not null
        Result = Table.SelectRows(
            #"Changed Type",
            (row) =>  
                List.AnyTrue(
                    List.Transform(ColumnsNamesForNullTest, each Record.Field(row, _) = null)
                ) 
                or
                Duration.TotalDays(DateTime.LocalNow() - row[Field D]) > 28
        )
    in
        Result