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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
don
Regular Visitor

Append column names in nested table from value of another column

Hello everyone, could I please get help from  anyone on how to rename all column names from the tables in "Custom" column and append them with the value from column "Code"

Nested tables.JPG

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

Use this code. Replace #"Grouped Rows" with your previous step name

= Table.FromRecords(Table.TransformRows(#"Grouped Rows", (r)=> [Code = r[Code], Custom = Table.TransformColumnNames(r[Custom], (x)=>x&Text.From(r[Code]))]))

View solution in original post

3 REPLIES 3
Vijay_A_Verma
Super User
Super User

Use this code. Replace #"Grouped Rows" with your previous step name

= Table.FromRecords(Table.TransformRows(#"Grouped Rows", (r)=> [Code = r[Code], Custom = Table.TransformColumnNames(r[Custom], (x)=>x&Text.From(r[Code]))]))

Thank you Vijay, it worked great.

Is there a way to rename columns that name which contains specific text, let's say rename columns that contains "abc" in the header only

Hi @don, check this. Remove ", Comparer.OrdinalIgnoreCase" from the code if you want case sensitive check.

dufoq3_0-1713253923273.png

 

let
    Source = #table(type table[Code=Int64.Type, Custom=table], {
        {6100, #table({"Column10", "Test abc 1", "Column20"}, {{1,2,3}})},
        {6200, #table({"Column10", "Test abc", "A_Abc_B"}, {{4,5,6}})}
    }),
    Ad_Renamed = Table.AddColumn(Source, "Renamed", each Table.RenameColumns([Custom], 
        [ a = List.Select(Table.ColumnNames([Custom]), (x)=> Text.Contains(x, "abc", Comparer.OrdinalIgnoreCase)),
          b = List.Zip({ a, List.Transform(a, (x)=> x & Text.From([Code])) })
        ][b]),
    type table)
in
    Ad_Renamed

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors