Forum Discussion
how to create a batch tree
- 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:
Hello jps_HHH
Use this DAX to create a calculated table
BatchTree =
UNION (
SELECTCOLUMNS(MainTable, "ParentLine", [Line no.], "ChildLine", [Line no.]),
SELECTCOLUMNS(
FILTER(
CROSSJOIN(MainTable, MainTable),
MainTable[Material 1] = MainTable_1[Product]
&& MainTable[Batch 1] = MainTable_1[Batch]
),
"ParentLine", MainTable_1[Line no.],
"ChildLine", MainTable[Line no.]
)
)
Thanks,
Pankaj Namekar | LinkedIn
If this solution helps, please accept it and give a kudos (Like), it would be greatly appreciated.
- jps_HHH1 year agoHelper II
thanks for your reply.
My batch tree could have 4 or 5 products.
Example:
Product A batch B20 is manufactured used Product XD, batch B80.
XD.B80 is manufactured used Product ED.C57.
ED.C57 is manufactured used Product CV.D90.
I would like to select product A and batch B20 and the system automatically filters
XD.B80
ED.C57
CV.D90