Forum Discussion
Vetri_BI
2 years agoFrequent Visitor
perform a simple matrix addition between two tables using power query
for my business requirement i need to add two matrix. and get a resultant matrix. i know how to do it if the the number of column is small and manually entering the columns. but for my case the numb...
- 2 years ago
Hi
= Table.FromColumns(
List.Transform(
List.Zip(
{Table.ToColumns(MatrixA),
Table.ToColumns(MatrixB)}),
each List.Transform(
List.Zip({_{0},_{1}}),
List.Sum)
)
)Stéphane
slorin
2 years agoSuper User
Hi
= Table.FromColumns(
List.Transform(
List.Zip(
{Table.ToColumns(MatrixA),
Table.ToColumns(MatrixB)}),
each List.Transform(
List.Zip({_{0},_{1}}),
List.Sum)
)
)
Stéphane
- Vetri_BI2 years agoFrequent Visitor
slorin Thanks a lot for your reply , the solution worked like magic(My brain cannot comprehend how loop/iteration works in Power query).
for people who want to use this matrix addition query here is the complete power query. that i copied from slorin 's solution.
//************
let
A = Table.FromRows(
{
{1, 2},
{3, 4}
}),
B = Table.FromRows(
{
{5, 6},
{7, 8}
}),
Addition = (MatrixA , MatrixB) => {
Table.FromColumns(
List.Transform(
List.Zip(
{Table.ToColumns(MatrixA),
Table.ToColumns(MatrixB)}
),
each List.Transform(
List.Zip({_{0},_{1}}),
List.Sum)
)
)
}
,
resultMatrix = Addition(A,B){0}
in
resultMatrix//************