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.
Hi, I am trying to transform :
#"Inserted Multiplication" = Table.AddColumn(#"Renamed Columns", "Multiplication", each List.Product({[Column1], [Column2], [Column3], [Column4], [Column5], [ColumnBASE]}), Currency.Type),
and
#"Inserted Count" = Table.AddColumn(#"Added Index", "Count", each List.NonNullCount({[Column1], [Column2], [Column3], [Column4], [Column5]}), Int64.Type),
so that it can accomodate a variable list of columns (it needs to use all the columns with a name starting with "Column")
I am replacing {[Column1], [Column2], [Column3], [Column4], [Column5]} by
List.Select(Table.ColumnNames(#"Added Index"), each Text.Contains(_,"Column"))
but the count returns the same value for each row (which is incorrect) and the list.Product returns an error.
Seems to be a type error ( list is not considered as a list of columns?)
Can this be solved ? thank you
Solved! Go to Solution.
It might be easier to unpivot your data to do this; however, here is an example of how to do this with some example data. To see how it works, just create a blank query, go to Advanced Editor, and replace the text there with the M code below.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTICYmMgNlGK1YlG4ukomSrFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Text = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, {"Column2", Int64.Type}, {"Column3", Int64.Type}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
#"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each #"Added Index"{[Index]}),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each List.Sum(Record.ToList(Record.SelectFields([Custom], List.Select(Table.ColumnNames(#"Added Index"), each Text.Contains(_, "Column"))))))
in
#"Added Custom1"
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
It might be easier to unpivot your data to do this; however, here is an example of how to do this with some example data. To see how it works, just create a blank query, go to Advanced Editor, and replace the text there with the M code below.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTICYmMgNlGK1YlG4ukomSrFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Text = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, {"Column2", Int64.Type}, {"Column3", Int64.Type}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
#"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each #"Added Index"{[Index]}),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each List.Sum(Record.ToList(Record.SelectFields([Custom], List.Select(Table.ColumnNames(#"Added Index"), each Text.Contains(_, "Column"))))))
in
#"Added Custom1"
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
HI Pat,
It works ! Legend !
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
116 | |
102 | |
78 | |
77 | |
49 |
User | Count |
---|---|
145 | |
108 | |
107 | |
89 | |
61 |