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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
gvg
Post Prodigy
Post Prodigy

Get substring of every column in table

Hi folks,

I am looking to figure out how to get a substring of every column in a table with a variable number of columns. My code looks like this but it is not working. It is expected to take a substring beginning with the 3rd character in every column regardless how many columns the table has.

let 
  Source = myTable,
  myColumns = Table.ColumnNames(Source),
  #"Replaced Value1" = Table.ReplaceValue(Source,
      each myColumns,
      each Text.Middle(myColumns,3),
      Replacer.ReplaceValue,myColumns)
in
    #"Replaced Value1"

What am I missing here? I am not really comfortable with using each in PQ.

Thanks.

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

It's vital to understand use of different each and its different evaluation contextin in different functions.

let
    Source = myTable,
    myColumns = Table.ColumnNames(Source),
    Custom1 = List.Accumulate(myColumns, Source, (s,c) => Table.ReplaceValue(s, each Record.Field(_, c), each Text.Start(Text.From(Record.Field(_, c)), 3), Replacer.ReplaceValue, {c}))
in
    Custom1

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

2 REPLIES 2
CNENFRNL
Community Champion
Community Champion

It's vital to understand use of different each and its different evaluation contextin in different functions.

let
    Source = myTable,
    myColumns = Table.ColumnNames(Source),
    Custom1 = List.Accumulate(myColumns, Source, (s,c) => Table.ReplaceValue(s, each Record.Field(_, c), each Text.Start(Text.From(Record.Field(_, c)), 3), Replacer.ReplaceValue, {c}))
in
    Custom1

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Yes, this works. Thank you !

What would you recommend to read about each? I find Microsoft documentation being very sparse.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.