Forum Discussion
rpiboy_1
Helper V
3 years agoCan'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,
#"Head...
- 3 years ago
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"))
ImkeF
Community Champion
3 years agoHi 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?
rpiboy_1
Helper V
3 years agoLet's say I have a table like this:
| Col1 | Col2 | StatusCol1 | StatusCol2 | StatusCol3 |
| <value> | <value> | A | BB | CCC |
| <value> | <value> | Z | XX | YYY |
| <value> | <value> | CCC | BB | A |
I want to merge all columns with 'status' in the name as a new column, so I get this:
| Col1 | Col2 | StatusCol1 | StatusCol2 | StatusCol3 | Merged |
| <value> | <value> | A | BB | CCC | ABBCCC |
| <value> | <value> | Z | XX | YYY | ZXXYYY |
| <value> | <value> | CCC | BB | A | CCCBBA |
Right now, I'm getting:
| Col1 | Col2 | StatusCol1 | StatusCol2 | StatusCol3 | Merged |
| <value> | <value> | A | BB | CCC | StatusCol1StatusCol2StatusCol3 |
| <value> | <value> | Z | XX | YYY | StatusCol1StatusCol2StatusCol3 |
| <value> | <value> | CCC | BB | A | StatusCol1StatusCol2StatusCol3 |