Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Hambach
Frequent Visitor

Multiply multiple columns by factor from another table in ideally one step?

Hi, I have two tables and I would like to multiply several income columns (more than 20 in the real table, ideally all in one step) form the first one by a factor from another table:

 

Project IDLossesIncome 1Income 2
1345
2212

 

Project IDFactor
12
23

 

So you get:

 

Project IDLossesIncome 1Income 2
13810
2236

 

Since in the real table it will be a lot of columns, is there a convenient formula that will do it in one or just a few steps, directly transforming the existing columns? So I don't have to to the steps of "Create new calculated column, delete the old one, rename the new one" for every single column.

 

Thank you!

3 ACCEPTED SOLUTIONS
wdx223_Daniel
Community Champion
Community Champion

NewStep=Table.ReplaceValue(Table1,each [Project ID],"",(x,y,z)=>x*Table2{[Project ID=y]}?[Factor]? ??x,List.Select(Table.ColumnNames(Table1),each Text.StartsWith(_,"Income")))

View solution in original post

Anonymous
Not applicable

Hi @Hambach 

 

Here is another method for your reference. Use Unpivot/Pivot columns and Merge queries. 

Unpivot columns - Power Query | Microsoft Learn

Pivot columns feature description - Power Query | Microsoft Learn

Merge queries overview - Power Query | Microsoft Learn

Table 1:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIGYhMgNlWK1YlWMgKyQNgQTMfGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Project ID" = _t, Losses = _t, #"Income 1" = _t, #"Income 2" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Project ID", Int64.Type}, {"Losses", Int64.Type}, {"Income 1", Int64.Type}, {"Income 2", Int64.Type}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Project ID"}, "Attribute", "Value"),
    #"Merged Queries" = Table.NestedJoin(#"Unpivoted Other Columns", {"Project ID"}, FactorTable, {"Project ID"}, "FactorTable", JoinKind.LeftOuter),
    #"Expanded FactorTable" = Table.ExpandTableColumn(#"Merged Queries", "FactorTable", {"Factor"}, {"Factor"}),
    #"Added Custom" = Table.AddColumn(#"Expanded FactorTable", "NewValue", each if Text.StartsWith([Attribute], "Income") then [Value]*[Factor] else [Value]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Value", "Factor"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Attribute]), "Attribute", "NewValue")
in
    #"Pivoted Column"

 

Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!

View solution in original post

dufoq3
Community Champion
Community Champion

Hi @Hambach,

 

Result:

dufoq3_0-1717050277332.png

let
    DataTable = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIGYhMgNlWK1YlWMgKyQNgQTMfGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Project ID" = _t, Losses = _t, #"Income 1" = _t, #"Income 2" = _t]),
    FactorTable = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTJSitWJBpI6SsZKsbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Project ID" = _t, Factor = _t]),
    ChangedTypeDataTable = Table.TransformColumnTypes(DataTable,{{"Project ID", Int64.Type}, {"Losses", type number}, {"Income 1", type number}, {"Income 2", type number}}),
    ChangedTypeFactorTable = Table.TransformColumnTypes(FactorTable,{{"Project ID", Int64.Type}, {"Factor", Int64.Type}}),
    MergedQueries = Table.NestedJoin(ChangedTypeDataTable, {"Project ID"}, ChangedTypeFactorTable, {"Project ID"}, "FactorTable", JoinKind.LeftOuter),
    IncomeMultipliedByFactor = Table.ReplaceValue(MergedQueries,
        null,
        each [FactorTable][Factor]{0}?,
        (x,y,z)=> if z = null then x else x*z,
        List.Select(Table.ColumnNames(MergedQueries), each Text.Contains(_, "Income", Comparer.OrdinalIgnoreCase)) ),
    RemovedColumns = Table.RemoveColumns(IncomeMultipliedByFactor,{"FactorTable"}),
    RestoreTypes = Value.ReplaceType(RemovedColumns, Value.Type(ChangedTypeDataTable))
in
    RestoreTypes

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

3 REPLIES 3
dufoq3
Community Champion
Community Champion

Hi @Hambach,

 

Result:

dufoq3_0-1717050277332.png

let
    DataTable = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIGYhMgNlWK1YlWMgKyQNgQTMfGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Project ID" = _t, Losses = _t, #"Income 1" = _t, #"Income 2" = _t]),
    FactorTable = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTJSitWJBpI6SsZKsbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Project ID" = _t, Factor = _t]),
    ChangedTypeDataTable = Table.TransformColumnTypes(DataTable,{{"Project ID", Int64.Type}, {"Losses", type number}, {"Income 1", type number}, {"Income 2", type number}}),
    ChangedTypeFactorTable = Table.TransformColumnTypes(FactorTable,{{"Project ID", Int64.Type}, {"Factor", Int64.Type}}),
    MergedQueries = Table.NestedJoin(ChangedTypeDataTable, {"Project ID"}, ChangedTypeFactorTable, {"Project ID"}, "FactorTable", JoinKind.LeftOuter),
    IncomeMultipliedByFactor = Table.ReplaceValue(MergedQueries,
        null,
        each [FactorTable][Factor]{0}?,
        (x,y,z)=> if z = null then x else x*z,
        List.Select(Table.ColumnNames(MergedQueries), each Text.Contains(_, "Income", Comparer.OrdinalIgnoreCase)) ),
    RemovedColumns = Table.RemoveColumns(IncomeMultipliedByFactor,{"FactorTable"}),
    RestoreTypes = Value.ReplaceType(RemovedColumns, Value.Type(ChangedTypeDataTable))
in
    RestoreTypes

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Anonymous
Not applicable

Hi @Hambach 

 

Here is another method for your reference. Use Unpivot/Pivot columns and Merge queries. 

Unpivot columns - Power Query | Microsoft Learn

Pivot columns feature description - Power Query | Microsoft Learn

Merge queries overview - Power Query | Microsoft Learn

Table 1:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIGYhMgNlWK1YlWMgKyQNgQTMfGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Project ID" = _t, Losses = _t, #"Income 1" = _t, #"Income 2" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Project ID", Int64.Type}, {"Losses", Int64.Type}, {"Income 1", Int64.Type}, {"Income 2", Int64.Type}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Project ID"}, "Attribute", "Value"),
    #"Merged Queries" = Table.NestedJoin(#"Unpivoted Other Columns", {"Project ID"}, FactorTable, {"Project ID"}, "FactorTable", JoinKind.LeftOuter),
    #"Expanded FactorTable" = Table.ExpandTableColumn(#"Merged Queries", "FactorTable", {"Factor"}, {"Factor"}),
    #"Added Custom" = Table.AddColumn(#"Expanded FactorTable", "NewValue", each if Text.StartsWith([Attribute], "Income") then [Value]*[Factor] else [Value]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Value", "Factor"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Attribute]), "Attribute", "NewValue")
in
    #"Pivoted Column"

 

Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!

wdx223_Daniel
Community Champion
Community Champion

NewStep=Table.ReplaceValue(Table1,each [Project ID],"",(x,y,z)=>x*Table2{[Project ID=y]}?[Factor]? ??x,List.Select(Table.ColumnNames(Table1),each Text.StartsWith(_,"Income")))

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.