Forum Discussion

Nyx's avatar
Nyx
Frequent Visitor
3 years ago
Solved

List generation from minimum value and maximum value of multiple columns of a table.

Attempting to generate a list of values when the upper and lower limits are determined by the min and max values from any cell of multiple columns. Currently produces Error in 1 cell under "List".

 

 

let
Source = List.Generate(() => List.Min({Column[1],Column[2],Column[3]},0), each _ <= List.Max({Column[1],Column[2],Column[3]}), each _ + 1)
in
#"Source"

  • Hi Nyx,

     

    You are getting htis error because the code tries to find min/max between the lists (not the numbers), kind of List.Min({List1, List2, List3}). PQ just does not know how to compare them (and after all this is not what you want anyway). You can fix it by combining all the lists into a single one using List.Combine:

    let
    
        Column = 
            let
                Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIGYjOlWJ1oJSMgywSIzcE8kLgpEFuAeSZgVTpKlkqxsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"1" = _t, #"2" = _t, #"3" = _t]),
                #"Changed Type" = Table.TransformColumnTypes(Source,{{"1", Int64.Type}, {"2", Int64.Type}, {"3", Int64.Type}})
            in
                #"Changed Type",
    
        Source = List.Generate(() => List.Min(List.Combine({Column[1],Column[2],Column[3]}) & {0}), each _ <= List.Max(List.Combine({Column[1],Column[2],Column[3]})), each _ + 1)
    in
        #"Source"

    Cheers,

    John

     

1 Reply

  • jbwtp's avatar
    jbwtp
    Icon for Memorable Member rankMemorable Member

    Hi Nyx,

     

    You are getting htis error because the code tries to find min/max between the lists (not the numbers), kind of List.Min({List1, List2, List3}). PQ just does not know how to compare them (and after all this is not what you want anyway). You can fix it by combining all the lists into a single one using List.Combine:

    let
    
        Column = 
            let
                Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIGYjOlWJ1oJSMgywSIzcE8kLgpEFuAeSZgVTpKlkqxsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"1" = _t, #"2" = _t, #"3" = _t]),
                #"Changed Type" = Table.TransformColumnTypes(Source,{{"1", Int64.Type}, {"2", Int64.Type}, {"3", Int64.Type}})
            in
                #"Changed Type",
    
        Source = List.Generate(() => List.Min(List.Combine({Column[1],Column[2],Column[3]}) & {0}), each _ <= List.Max(List.Combine({Column[1],Column[2],Column[3]})), each _ + 1)
    in
        #"Source"

    Cheers,

    John