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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Zaibass81
Helper I
Helper I

BOM Extended Quantity

Hi All,

 

I am new to this group 🙂

 

i am looking for sulution to built M code (preferable ) or DAX to get BOM extended Qty, please see example attached:

2019-11-13_17h43_01.png 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Zaibass81 

 

as far as I understand what the LOOKUP does in your Excel example, this is the code below:

 

Main table:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUQIiAz0jQ6VYnWglIwjfCJkDlESRMwHzjCE8iDYTqEpMGRycWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Level = _t, Part = _t, Quantity = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Level", Int64.Type}, {"Part", type text}, {"Quantity", type number}}),
    
    
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Custom", (r) => if r[Level] = 1 then r[Quantity] else r[Quantity] * fBOM(#"Added Index", r))
in
    #"Added Custom"

 

fBOM function:

(pTable as table, r as record)=>
    let
        LookUp = Table.LastN(Table.SelectRows(pTable , each [Index] < r[Index] and [Level] = r[Level]-1), 1),
        Output = if LookUp[Level]{0} = 1 then LookUp[Quantity]{0} else LookUp[Quantity]{0} * fBOM(pTable, LookUp{0})
    in 
        Output

 

Just be aware, this is a brutal-force approach and may run slow when applied to a sizable (few thousand rows) table.

 

Kind regards,

JB

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Zaibass81 

 

as far as I understand what the LOOKUP does in your Excel example, this is the code below:

 

Main table:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUQIiAz0jQ6VYnWglIwjfCJkDlESRMwHzjCE8iDYTqEpMGRycWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Level = _t, Part = _t, Quantity = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Level", Int64.Type}, {"Part", type text}, {"Quantity", type number}}),
    
    
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Custom", (r) => if r[Level] = 1 then r[Quantity] else r[Quantity] * fBOM(#"Added Index", r))
in
    #"Added Custom"

 

fBOM function:

(pTable as table, r as record)=>
    let
        LookUp = Table.LastN(Table.SelectRows(pTable , each [Index] < r[Index] and [Level] = r[Level]-1), 1),
        Output = if LookUp[Level]{0} = 1 then LookUp[Quantity]{0} else LookUp[Quantity]{0} * fBOM(pTable, LookUp{0})
    in 
        Output

 

Just be aware, this is a brutal-force approach and may run slow when applied to a sizable (few thousand rows) table.

 

Kind regards,

JB

 

Thank you Sir, it did worked well, however as you mentioned is runing wery slow when applied to a sizable table

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors