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
rpiboy_1
Helper V
Helper V

Can't seem to implement Record.FieldValues properly

I still keep having issues on how to implement Record.FieldValues in given situations. Here is the M code I have currently.

 

 

 

let
    ColumnFilter = "Status",
    Source = Table1,
    #"Headers" = Table.ColumnNames(Source),
    #"Converted to Table" = Table.FromList(Headers, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Added Conditional Column" = Table.AddColumn(#"Converted to Table", "Custom", each if Text.Contains([Column1], ColumnFilter) then [Column1] else null),
    #"Removed Columns" = Table.RemoveColumns(#"Added Conditional Column",{"Column1"}),
    #"Filtered Rows" = Table.SelectRows(#"Removed Columns", each ([Custom] <> null)),
    #"HeaderList" = #"Filtered Rows"[Custom],    
    #"Merged Columns" = Table.AddColumn(Source, "Merged", each Text.Combine(#"HeaderList", ""), type text)

in
#"Merged Columns"

 

 

 

The problem I'm having is my #"Merged Columns" statement is literally merging the Column Header Values, for all rows, as opposed to merging the row values of the columns defined by the #"HeaderList" statement. I know I need to use Record.FieldValues in some form, or some Record.x function, but I'm not having any luck. Any pointers, and explanation would be much appreciated.

1 ACCEPTED SOLUTION
ImkeF
Community Champion
Community Champion

Hi @rpiboy_1 ,
thanks, that's helpful.
You would have to adjust like this:

let
    ColumnFilter = "Status",
    Source = Table1,
    #"Headers" = Table.ColumnNames(Source),
    #"Converted to Table" = Table.FromList(Headers, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Added Conditional Column" = Table.AddColumn(#"Converted to Table", "Custom", each if Text.Contains([Column1], ColumnFilter) then [Column1] else null),
    #"Removed Columns" = Table.RemoveColumns(#"Added Conditional Column",{"Column1"}),
    #"Filtered Rows" = Table.SelectRows(#"Removed Columns", each ([Custom] <> null)),
    #"HeaderList" = #"Filtered Rows"[Custom],    
    #"Merged Columns" = Table.AddColumn(Source, "Merged", each Text.Combine(Record.FieldValues(Record.SelectFields(_,#"HeaderList")), ""), type text)

in
#"Merged Columns"

so first you select the relevant fields of the records and then you fetch their values afterwards:
Record.FieldValues(Record.SelectFields(_,#"HeaderList"))

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

4 REPLIES 4
ImkeF
Community Champion
Community Champion

Hi @rpiboy_1 ,
thanks, that's helpful.
You would have to adjust like this:

let
    ColumnFilter = "Status",
    Source = Table1,
    #"Headers" = Table.ColumnNames(Source),
    #"Converted to Table" = Table.FromList(Headers, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Added Conditional Column" = Table.AddColumn(#"Converted to Table", "Custom", each if Text.Contains([Column1], ColumnFilter) then [Column1] else null),
    #"Removed Columns" = Table.RemoveColumns(#"Added Conditional Column",{"Column1"}),
    #"Filtered Rows" = Table.SelectRows(#"Removed Columns", each ([Custom] <> null)),
    #"HeaderList" = #"Filtered Rows"[Custom],    
    #"Merged Columns" = Table.AddColumn(Source, "Merged", each Text.Combine(Record.FieldValues(Record.SelectFields(_,#"HeaderList")), ""), type text)

in
#"Merged Columns"

so first you select the relevant fields of the records and then you fetch their values afterwards:
Record.FieldValues(Record.SelectFields(_,#"HeaderList"))

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Perfect, thanks so much, and the explanation makes sense. Seems like I was generally moving in the right direction, just didn't realize the need to apply the Record.SelectFields function.

ImkeF
Community Champion
Community Champion

Hi @rpiboy_1 ,
having problems understanding what you want to achieve here. Could you please post a link to a file with some sample data, giving source data and expected result? 

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Let's say I have a table like this:

 

Col1Col2StatusCol1StatusCol2StatusCol3
<value><value>ABBCCC
<value><value>ZXXYYY
<value><value>CCCBBA

 

I want to merge all columns with 'status' in the name as a new column, so I get this:

 

Col1Col2StatusCol1StatusCol2StatusCol3Merged
<value><value>ABBCCCABBCCC
<value><value>ZXXYYYZXXYYY
<value><value>CCCBBA

CCCBBA

 

Right now, I'm getting:

Col1Col2StatusCol1StatusCol2StatusCol3Merged
<value><value>ABBCCCStatusCol1StatusCol2StatusCol3
<value><value>ZXXYYYStatusCol1StatusCol2StatusCol3
<value><value>CCCBBA

StatusCol1StatusCol2StatusCol3

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!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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