Forum Discussion
jps_HHH
1 year agoHelper II
how to create a batch tree
I have a table with multiple lines with the following info: Line no. | Product | Batch | Material 1 | Batch 1 | etc 123 A B20 XD ...
- 1 year ago
Hi jps_HHH
Thanks for reaching out ot the fabric community.
Please do follow the below steps to resolve the issue.- Unpivot your material and batch columns into a parent-child relations table using:
Table.UnpivotOtherColumns(
RawBatches,
{"Line no.","Product","Batch"},
"MaterialProduct",
"MaterialBatch"
)
``` :contentReference[oaicite:0]{index=0} - Add ParentKey = [Product] & "|" & [Batch] and ChildKey = [MaterialProduct] & "|" & [MaterialBatch] columns to the relations table.
- Create a blank query BatchTree and paste in an M script that:
-
Starts with a list {SelectedBatch}
- Uses List.Generate to repeatedly find rows where ParentKey is in the current list, collect their ChildKeys, and stop when no new keys appear https://learn.microsoft.com/en-us/powerquery-m/list-generate
-
- Filter the relations table to only rows whose ParentKey is in the final expanded key list.
- Merge those filtered rows back to RawBatches on the matching key to retrieve full row details.
- Expose SelectedBatch as a slicer (via a disconnected parameter table or What-If parameter) so users pick e.g. A|B20.
- Bind your visual (table or matrix) to the BatchTree query—selecting a batch will now show it plus all downstream batches (XD|B80 → ED|C57 → CV|D90) at any depth.
If the above information is helpful, please give us Kudos and mark the response as Accepted as solution.
Best Regards,
Community Support Team _ C Srikanth. - Unpivot your material and batch columns into a parent-child relations table using:
v-csrikanth
1 year agoCommunity Support
Hi jps_HHH
Thanks for reaching out ot the fabric community.
Please do follow the below steps to resolve the issue.
- Unpivot your material and batch columns into a parent-child relations table using:
Table.UnpivotOtherColumns(
RawBatches,
{"Line no.","Product","Batch"},
"MaterialProduct",
"MaterialBatch"
)
``` :contentReference[oaicite:0]{index=0} - Add ParentKey = [Product] & "|" & [Batch] and ChildKey = [MaterialProduct] & "|" & [MaterialBatch] columns to the relations table.
- Create a blank query BatchTree and paste in an M script that:
-
Starts with a list {SelectedBatch}
- Uses List.Generate to repeatedly find rows where ParentKey is in the current list, collect their ChildKeys, and stop when no new keys appear https://learn.microsoft.com/en-us/powerquery-m/list-generate
-
- Filter the relations table to only rows whose ParentKey is in the final expanded key list.
- Merge those filtered rows back to RawBatches on the matching key to retrieve full row details.
- Expose SelectedBatch as a slicer (via a disconnected parameter table or What-If parameter) so users pick e.g. A|B20.
- Bind your visual (table or matrix) to the BatchTree query—selecting a batch will now show it plus all downstream batches (XD|B80 → ED|C57 → CV|D90) at any depth.
If the above information is helpful, please give us Kudos and mark the response as Accepted as solution.
Best Regards,
Community Support Team _ C Srikanth.