Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Multiply two or more tables

Hi, 

 

I am new to power BI and i would like to combine two main tables into one. However, they are not of the same size. 

 

Table 1:

ProductCodePercentage
Prod1A30%
Prod1B30%
Prod1C40%
Prod2A25%
Prod2F25%
Prod2H50%
Prod3I15%
Prod3J25%
Prod3D25%
Prod3E35%
Prod4F14%
Prod4C21%
Prod4G30%
Prod4B35%

 

Table 2:

CategoryCodeQ1 2018Q2 2018Q3 2018Q4 2018
1A1.11.21.31.3
2B0.80.80.70.6
3C3.23.23.13
3D0.40.30.20.1
2E0.70.60.650.62
1F2.52.42.62.7
2G3.13.23.23.1
3H4.44.44.34.2
1I2.22.12.22.1

 

This is how the data is being stored. I would like to have the following output:

ProductQ1 2018Q2 2018Q3 2018Q4 2018
Prod1    
Prod2    
Prod3    
Prod4    

 

How do i create the table?

 

Thank you!

 

  • Hi.Anonymous

     You can achieve the view by this

     

    let
        Source = Web.Page(Web.Contents("https://community.powerbi.com/t5/Desktop/Multiply-two-or-more-tables/m-p/662123#M318163")),
        Data0 = Source{0}[Data],
        #"Promoted Headers" = Table.PromoteHeaders(Data0, [PromoteAllScalars=true]),
        #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Product", type text}, {"Code", type text}, {"Percentage", Percentage.Type}})
    in
        #"Changed Type"

    Table 0

    let
        Source = Web.Page(Web.Contents("https://community.powerbi.com/t5/Desktop/Multiply-two-or-more-tables/m-p/662123#M318163")),
        Data1 = Source{1}[Data],
        #"Promoted Headers" = Table.PromoteHeaders(Data1, [PromoteAllScalars=true]),
        #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Category", Int64.Type}, {"Code", type text}, {"Q1 2018", type number}, {"Q2 2018", type number}, {"Q3 2018", type number}, {"Q4 2018", type number}}),
        #"Merged Queries" = Table.NestedJoin(#"Changed Type",{"Code"},#"Table 0",{"Code"},"Table 0",JoinKind.LeftOuter),
        #"Expanded Table 0" = Table.ExpandTableColumn(#"Merged Queries", "Table 0", {"Product"}, {"Product"}),
        #"Removed Other Columns" = Table.SelectColumns(#"Expanded Table 0",{"Product", "Q1 2018", "Q2 2018", "Q3 2018", "Q4 2018"}),
        #"Grouped Rows" = Table.Group(#"Removed Other Columns", {"Product"}, {{"Q1 2018", each List.Sum([Q1 2018]), type number}, {"Q2 2018", each List.Sum([Q2 2018]), type number}, {"Q3 2018", each List.Sum([Q3 2018]), type number}, {"Q4 2018", each List.Sum([Q4 2018]), type number}})
    in
        #"Grouped Rows"

    Table 1

     

2 Replies

  • smpa01's avatar
    smpa01
    Icon for Community Champion rankCommunity Champion

    Hi.Anonymous

     You can achieve the view by this

     

    let
        Source = Web.Page(Web.Contents("https://community.powerbi.com/t5/Desktop/Multiply-two-or-more-tables/m-p/662123#M318163")),
        Data0 = Source{0}[Data],
        #"Promoted Headers" = Table.PromoteHeaders(Data0, [PromoteAllScalars=true]),
        #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Product", type text}, {"Code", type text}, {"Percentage", Percentage.Type}})
    in
        #"Changed Type"

    Table 0

    let
        Source = Web.Page(Web.Contents("https://community.powerbi.com/t5/Desktop/Multiply-two-or-more-tables/m-p/662123#M318163")),
        Data1 = Source{1}[Data],
        #"Promoted Headers" = Table.PromoteHeaders(Data1, [PromoteAllScalars=true]),
        #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Category", Int64.Type}, {"Code", type text}, {"Q1 2018", type number}, {"Q2 2018", type number}, {"Q3 2018", type number}, {"Q4 2018", type number}}),
        #"Merged Queries" = Table.NestedJoin(#"Changed Type",{"Code"},#"Table 0",{"Code"},"Table 0",JoinKind.LeftOuter),
        #"Expanded Table 0" = Table.ExpandTableColumn(#"Merged Queries", "Table 0", {"Product"}, {"Product"}),
        #"Removed Other Columns" = Table.SelectColumns(#"Expanded Table 0",{"Product", "Q1 2018", "Q2 2018", "Q3 2018", "Q4 2018"}),
        #"Grouped Rows" = Table.Group(#"Removed Other Columns", {"Product"}, {{"Q1 2018", each List.Sum([Q1 2018]), type number}, {"Q2 2018", each List.Sum([Q2 2018]), type number}, {"Q3 2018", each List.Sum([Q3 2018]), type number}, {"Q4 2018", each List.Sum([Q4 2018]), type number}})
    in
        #"Grouped Rows"

    Table 1

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you!