Forum Discussion

ItoDiaz's avatar
ItoDiaz
Helper I
6 years ago
Solved

Expression.Evaluate with List.MatchesAny

Hello all,   This is my second post here as I am new using Power BI.   I would need some help regarding a function that I try to use in a query. I have adapted a solution provided by Smauro  for ...
  • camargos88's avatar
    6 years ago

    Hi ItoDiaz ,

     

    Try this code:

     

    let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIyMDLQNTDSNQBxDKDYEI5jdaKVjNCVYWKQMmNsygxQaJAyhKXGCEsxTTNCV4aMIe5EtdQYp6WxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [No = _t, Date = _t, A = _t, B = _t, C = _t, D = _t, E = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"No", Int64.Type}, {"Date", type date}, {"A", Int64.Type}, {"B", Int64.Type}, {"C", Int64.Type}, {"D", Int64.Type}, {"E", Int64.Type}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"No", "Date"}, "Attribute", "Value"),
    #"Added Custom" = Table.AddColumn(#"Unpivoted Other Columns", "Custom", each if [Value] <= 0.6 then true else false),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Value"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Attribute]), "Attribute", "Custom"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Pivoted Column",{{"No", Int64.Type}, {"Date", type date}, {"A", type logical}, {"B", type logical}, {"C", type logical}, {"D", type logical}, {"E", type logical}})
    in
    #"Changed Type1"

     

     

  • Smauro's avatar
    6 years ago

    Hi ItoDiaz 

     

    Supposing you'd like to use a solution like then one you refer to, then:

    1) Get a list of the Columns:

        Columns = List.Select(Table.ColumnNames(PreviousStep), each _ <> "Date"),

     

    2a) If your [Date] is distinct, then no need for grouping, you could just Transform the relevant columns:

        TransformList = List.Transform(Columns, each {_, (curr) => curr <= 0.6, Logical.Type}),
        Transform = Table.TransformColumns(PreviousStep,TransformList),

     

    2b) If your [Date] is not distinct, then you can use:

        GroupList = List.Transform(Columns, each {_, Expression.Evaluate( "each List.Min(["& _ & "]) <= 0.6", [List.Min = List.Min]), Logical.Type}),
        Group = Table.Group(PreviousStep, {"Date"}, GroupList),

     

    Note here that List.Min works like List.MatchesAny for numbers: If there is at least one value <=0.6 then the min will also be <=0.6

     

     

    Cheers,
    smauro