Forum Discussion

tjgagner's avatar
tjgagner
Frequent Visitor
1 year ago
Solved

Generate Recursive Bill of Material

I have a table imported into PowerBI from that has the relation between a top-level Bill-of-Material part number "BOM Material" and child part numbers "Component Material".  The challenge I am having...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Thanks for lbendlin's concern about this issue.

     

    Hi, tjgagner 

    I am glad to help you.

     

    Perhaps you can refer to my DAX to create a calculation table:

     

    FlattenedBOM =
    UNION (
        SELECTCOLUMNS (
            FILTER (
                'OriginalTable',
                'OriginalTable'[BOM Material]
                    IN SELECTCOLUMNS ( 'OriginalTable', 'OriginalTable'[Component Material] )
                        = FALSE ()
            ),
            "BOM Material", [BOM Material],
            "Component Material", [Component Material],
            "Level", 1
        ),
        ADDCOLUMNS (
            SELECTCOLUMNS (
                FILTER (
                    CROSSJOIN (
                        'OriginalTable',
                        SELECTCOLUMNS (
                            'OriginalTable',
                            "BOM Material2", 'OriginalTable'[BOM Material],
                            "Component Material2", 'OriginalTable'[Component Material]
                        )
                    ),
                    [BOM Material2] = [Component Material]
                ),
                [BOM Material],
                "Component Material", [Component Material2]
            ),
            "Level", 2
        )
    )
    

     

     

    Result:

     


    I have attached the pbix for this example below, I hope it helps!

     

     

    I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
    Best Regards,
    Fen Ling,
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.