Forum Discussion

AJ2960710's avatar
AJ2960710
Frequent Visitor
1 year ago
Solved

Multiple if statement and concatenating a result.

I am trying to test 20 conditions on a table with different (tests such as [value] should not be less than 0, [rate] should not be more than 1, date should not be older than 2024 etc.). Is there an e...
  • dufoq3's avatar
    1 year ago

    Hi AJ2960710, check this:

     

    Output

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Tc3JCQAxDAPAXvyOQT4S0ktI/22sDwj78WOE5HNIaBBGXoUaYzIW3XFoJjX7jwVVsE6SGVIJ7zBvRyCLlnsVVF9DGV6JVeL2vsR/660VttqFsWvrfg==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [value = _t, rate = _t, date = _t]),
        ChangedType = Table.TransformColumnTypes(Source,{{"value", Int64.Type}, {"rate", type number}, {"date", type date}}, "sk-SK"),
        Ad_ConditionsCheck = Table.AddColumn(ChangedType, "Check", each
            [ conditions = { [value] >= 0, [rate] <= 1, [date] >= #date(2024,1,1) },
              b = List.Transform(List.Positions(conditions), (x)=> "Condition " & Text.From(x+1) & " " & {"not met", "met"}{Byte.From(conditions{x})}),
              c = Text.Combine(b, " | ")
            ][c], type text)
    in
        Ad_ConditionsCheck