Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreShape the future of the Fabric Community! Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions. Take survey.
Hi,
Very new to PowerBI, I have a question around returning mutliple values from a table based on a single value in another.
Example is:
Table 1
Product ID | Product Name | Quantity |
1234 | Stapler 1 | 1 |
Table 2
Product ID | Product Name | Components | Quantity |
2345 | Stapler 2 | Stapler v2 | 1 |
Staple Pack x100 | 2 | ||
4567 | Stapler 3 | Stapler v3 | 1 |
Staple Pack x 50 | 2 | ||
1234 | Stapler 1 | Stapler v1 | 1 |
Staple Pack x 25 | 3 | ||
Staple Remover | 1 |
I can use the Product ID in both Tables as a join, but I dont know how I can add a column into Table 1 so that it would then show all the components from Table 2 against the matching Product ID?
Hoping this is easy but any guidance would be great.
Solved! Go to Solution.
you have to edit Table1 and Table2 step. Delete whole code and replace it with your Table1 reference, i.e. if your Table1 reference is MyTable1 then replace this whole code with = MyTable1 (if you have some special characters or space in table name i.e My Table1, you have to write it like this: #"My Table1"
Do the same for Table2.
Hi Dufoq3,
Thank you for taking the time to put this together. I am going to have a look at it hopefully get it working.
Thanks.
Hi @EduardoM83,
you should use Merge Queries UI button, but before that you have to do some additional steps. You can check that steps here (in this example both tables created in same query). You will be probably confused - but you can click on every single step and try to understand. BTW. Table1 and Table2 steps (based on JSON) - it is just a raw data which I created via UI buddon Enter Data.
I hope this will help you. (Don't spend time with Table2_ReplaceValue step please. At this moment you will probably don't understand how it works).
let
Table1 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNlHSUQouSSzISS1SMASyDZViYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Product ID" = _t, #"Product Name" = _t, Quantity = _t]),
Table2 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjI2MVXSUQouSSzISS1SMEJil4E4hkqxOtFKCkCWAlxKISAxOVuhwtDAAChkhKIAgkEiJqZm5kiGGSMbbKyA32QFU3wmGwLdjGSaIbLJhgQMNgJ51hibgqDU3Pyy1CKI/lgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Product ID" = _t, #"Product Name" = _t, Components = _t, Quantity = _t]),
Table2_ReplacedValue = Table.ReplaceValue(Table2,
null,
null,
(x,y,z)=> if Text.Trim(x) = "" then null else x,
{"Product ID", "Product Name", "Components", "Quantity"}),
Table2_FilledDown = Table.FillDown(Table2_ReplacedValue,{"Product ID"}),
#"Merged Queries" = Table.NestedJoin(Table1, {"Product ID"}, Table2_FilledDown, {"Product ID"}, "Table2", JoinKind.LeftOuter),
#"Expanded Table2" = Table.ExpandTableColumn(#"Merged Queries", "Table2", {"Product Name", "Components", "Quantity"}, {"Table2.Product Name", "Table2.Components", "Table2.Quantity"})
in
#"Expanded Table2"
Hi Dufoq3,
I managed to get this to work which is great, but if I add an additional row in table 1, lets say for Product 2345, it doesnt add that to the edited table. Is that possible?
Thanks again.
you have to edit Table1 and Table2 step. Delete whole code and replace it with your Table1 reference, i.e. if your Table1 reference is MyTable1 then replace this whole code with = MyTable1 (if you have some special characters or space in table name i.e My Table1, you have to write it like this: #"My Table1"
Do the same for Table2.
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Check out the November 2024 Power BI update to learn about new features.
User | Count |
---|---|
24 | |
13 | |
12 | |
11 | |
8 |
User | Count |
---|---|
44 | |
26 | |
16 | |
16 | |
12 |