Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
tjgagner
Regular Visitor

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 is that child "Component" part numbers themselves might be "BOM materials" I would like to see a flattened version of the Bill of Material with all component part numbers and the different levels represented.

 

The approach I am thinking about taking is populating a New Table with a query from the original, which includes recursion to get to a flat BOM like shown below.

tjgagner_0-1732125418387.png

 

How can I write a query that does this type of recursion?

2 ACCEPTED SOLUTIONS
v-fenling-msft
Community Support
Community Support

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:

vfenlingmsft_0-1732172501212.png

 


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.

View solution in original post

3 REPLIES 3
v-fenling-msft
Community Support
Community Support

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:

vfenlingmsft_0-1732172501212.png

 


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.

Thank you for your time answering my question. I did try and use this query but hung up on the calculation step ("working on it"). I will come back to it but am going to try the @lbendlin referenced solution as well.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.