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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
JNB3
New Member

Rename Nested Tables Based on Condition

Hello. I have a column named "Custom" which has nested tables, and I would like to conditionally rename the columns within the nested tables using the Text.Contains function. I thought my code below would achieve this, but it will only modify the parent column "Custom" rather than modifying the nested tables within. Thanks in advance for your time and help.

 

= let

Source = #"Added Custom",

RenamedColumns = Table.TransformColumnNames(Source, each if Text.Contains(_, "back", Comparer.OrdinalIgnoreCase)

then Text.Replace(_, _, "Back")  else _)

in RenamedColumns

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @JNB3 

 

You need to use Table.TransformColumns to apply the same transformation to each nested table within the Custom column.

 

On way to do this, is to first create a function that is similar to your RenamedColumns step (I called this RenameFunction), then apply this function using Table.TransformColumns in the ApplyRenameFunction step below.

 

let

  // Define a function that will be applied to each nested table
  RenameFunction = each Table.TransformColumnNames(
    _,
    each
      if Text.Contains(_, "back", Comparer.OrdinalIgnoreCase) then
        Text.Replace(_, _, "Back")
      else
        _
  ),
  // Source table
  Source = #"Added Custom",
  // Apply the function to each nested table in the Custom column
  ApplyRenameFunction = Table.TransformColumns(Source, {{"Custom", RenameFunction}})
in
  ApplyRenameFunction

Does this work for you?

 

Regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

2 REPLIES 2
OwenAuger
Super User
Super User

Hi @JNB3 

 

You need to use Table.TransformColumns to apply the same transformation to each nested table within the Custom column.

 

On way to do this, is to first create a function that is similar to your RenamedColumns step (I called this RenameFunction), then apply this function using Table.TransformColumns in the ApplyRenameFunction step below.

 

let

  // Define a function that will be applied to each nested table
  RenameFunction = each Table.TransformColumnNames(
    _,
    each
      if Text.Contains(_, "back", Comparer.OrdinalIgnoreCase) then
        Text.Replace(_, _, "Back")
      else
        _
  ),
  // Source table
  Source = #"Added Custom",
  // Apply the function to each nested table in the Custom column
  ApplyRenameFunction = Table.TransformColumns(Source, {{"Custom", RenameFunction}})
in
  ApplyRenameFunction

Does this work for you?

 

Regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

Thank you so much! This worked perfectly! Thanks again!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 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.