Forum Discussion
Anonymous
7 years agoNot applicable
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:
| Product | Code | Percentage |
| Prod1 | A | 30% |
| Prod1 | B | 30% |
| Prod1 | C | 40% |
| Prod2 | A | 25% |
| Prod2 | F | 25% |
| Prod2 | H | 50% |
| Prod3 | I | 15% |
| Prod3 | J | 25% |
| Prod3 | D | 25% |
| Prod3 | E | 35% |
| Prod4 | F | 14% |
| Prod4 | C | 21% |
| Prod4 | G | 30% |
| Prod4 | B | 35% |
Table 2:
| Category | Code | Q1 2018 | Q2 2018 | Q3 2018 | Q4 2018 |
| 1 | A | 1.1 | 1.2 | 1.3 | 1.3 |
| 2 | B | 0.8 | 0.8 | 0.7 | 0.6 |
| 3 | C | 3.2 | 3.2 | 3.1 | 3 |
| 3 | D | 0.4 | 0.3 | 0.2 | 0.1 |
| 2 | E | 0.7 | 0.6 | 0.65 | 0.62 |
| 1 | F | 2.5 | 2.4 | 2.6 | 2.7 |
| 2 | G | 3.1 | 3.2 | 3.2 | 3.1 |
| 3 | H | 4.4 | 4.4 | 4.3 | 4.2 |
| 1 | I | 2.2 | 2.1 | 2.2 | 2.1 |
This is how the data is being stored. I would like to have the following output:
| Product | Q1 2018 | Q2 2018 | Q3 2018 | Q4 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
Community 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
- AnonymousNot applicable
Thank you!