Forum Discussion

jps_HHH's avatar
jps_HHH
Helper II
1 year ago
Solved

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          ...
  • v-csrikanth's avatar
    1 year ago

    Hi jps_HHH 

    Thanks for reaching out ot the fabric community.
    Please do follow the below steps to resolve the issue.

    1. 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}
    2. Add ParentKey = [Product] & "|" & [Batch] and ChildKey = [MaterialProduct] & "|" & [MaterialBatch] columns to the relations table.
    3. Create a blank query BatchTree and paste in an M script that:
    4. Filter the relations table to only rows whose ParentKey is in the final expanded key list.
    5. Merge those filtered rows back to RawBatches on the matching key to retrieve full row details.
    6. Expose SelectedBatch as a slicer (via a disconnected parameter table or What-If parameter) so users pick e.g. A|B20.
    7. 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.