Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Dicken
Continued Contributor
Continued Contributor

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 = 5]
}    
so I want a list of records with each having fieds A to E,   the best way I've come up with is to use 
rename fields, and missing use null, 

let recs = { [ A = 1, C = 2 , D = 3] ,
[ C = 2, A = 1, E = 3] ,
[C = 4, E = 5]
} ,
rfh = List.Sort( List.Union(
List.Transform( recs, (x)=> Record.FieldNames(x))),
Order.Ascending)
in
List.Transform( recs, (x)=>
Record.ReorderFields(
Record.RenameFields( x, List.Zip( { rfh, rfh } ), MissingField.UseNull),
rfh ))

can any suggest a better method or a method that would allow a value of text  to be used instead of null ? 

Richad. 

1 ACCEPTED SOLUTION
ZhangKun
Super User
Super User

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

 

 

 

 

View solution in original post

5 REPLIES 5
Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Insert this as your next step

= List.Transform(recs, (x)=> Record.Combine({Record.FromList(List.Repeat({null}, 5), {"A".."E"}), x}))

Hence, your code would become

let
    recs = { [ A = 1, C = 2 , D = 3] ,
[ C = 2, A = 1, E = 3] ,
[C = 4, E = 5]}
in
    List.Transform(recs, (x)=> Record.Combine({Record.FromList(List.Repeat({null}, 5), {"A".."E"}), x})) 

 

Dicken
Continued Contributor
Continued Contributor

This has nothing to to do with the question but the above interface,
If I want to show code, what is the recomeneded method,  should I just add it and then put tags <> 
around? 

ZhangKun
Super User
Super User

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

 

 

 

 

Dicken
Continued Contributor
Continued Contributor

yes, that is what I wanted, not the table, but jsut a different way to achicve it, 
I tried to make a bit more dynamic;, 
full_RecordList = 
Record.ReorderFields(
Record.FromList(
List.Repeat( {null} , 5) ,
List.Union( List.Transform( Source, (x)=>
Record.FieldNames( x )))), {"A".."E"} )

I'm going to have to experiment, I was as to joing records,    I've tried a a few things like ; 

let arec = [ A = 1, C = 2, D = 3] ,
brec = [ B = 2, C = 10 , D = 10 , E = 5]
in brec & arec  
but changing whcih comes first, so is this right ;   
 they are joined, but if duplicate the first is used so here  A = 1 , no B in first so B = 2 from 2nd, 
C in both so C = 2 from first , D = 3 , E not present in first so E = 5 . 
I'll have to have a read up. 

Richad. 




Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors