Forum Discussion
MartinZ1
2 years agoRegular Visitor
Multiply each column by value in reference table (Key is column name)
Hello everyone, I'm looking for a way to multiply all values of each column in a table, by a multiplier that is determined by looking up the respective column name in another table. Example: Ta...
- Anonymous2 years ago
Hi MartinZ1
You can create two blank query , and put the following code to advanced editor
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcs7PMVTSUTJTitUBc4yAHBMYxxjIMVKKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column = _t, Value = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column", type text}, {"Value", Int64.Type}}) in #"Changed Type"let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlLSUTIGYkOlWJ1oMAskYqIUGwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Col1 = _t, Col2 = _t, Col3 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Col1", Int64.Type}, {"Col2", Int64.Type}, {"Col3", Int64.Type}}), #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {}, "Attribute", "Value"), #"Added Custom" = Table.AddColumn(#"Unpivoted Columns", "Custom", each List.Min(Table.SelectRows(Query1,(x)=>x[Column]=[Attribute])[Value])*[Value]), #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Value"}), #"Grouped Rows" = Table.Group(#"Removed Columns", {"Attribute"}, {{"Count", each Table.AddIndexColumn(_,"Index",1,1),type table}}), #"Expanded Count" = Table.ExpandTableColumn(#"Grouped Rows", "Count", {"Custom", "Index"}, {"Custom", "Index"}), #"Pivoted Column" = Table.Pivot(#"Expanded Count", List.Distinct(#"Expanded Count"[Attribute]), "Attribute", "Custom"), #"Removed Columns1" = Table.RemoveColumns(#"Pivoted Column",{"Index"}) in #"Removed Columns1"Output
Best Regards!
Yolo Zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.