Forum Discussion

Dicken's avatar
Dicken
Post Prodigy
1 year ago
Solved

Make records consistent ;

   Hi,    when working with liists I often end up with lists fo records and wnat to make the them same size,     example ;       { [ A = 1, C = 2 , D = 3] , [ C = 2, A = 1, E = 3] , [C = 4, E...
  • ZhangKun's avatar
    1 year ago

    If you just want to complete the field name, you can use the following code:

    let
        Source =  { 
            [ A = 1, C = 2 , D = 3] ,
            [ C = 2, A = 1, E = 3] ,
            [C = 4, E = 5]
        }, 
        result = List.Transform(
            Source, 
            each [A = null, B = null, C = null, D = null, E = null] & _
        )
    in
        result

    If you want to convert the records into a table and complete all the columns, you can use the following code:

    let
        Source =  { 
            [ A = 1, C = 2 , D = 3] ,
            [ C = 2, A = 1, E = 3] ,
            [C = 4, E = 5]
        }, 
        result = Table.FromRecords(
            Source, 
            type table [A = nullable text, B = nullable text, C = nullable text, D = nullable text, E = nullable text], 
            MissingField.UseNull
        )
    in
        result