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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Alberto95
Frequent Visitor

Product from tables related 1-n

Hi, i have a problem with the relationship 1-n. i need to calculate the product from different tables where in the first table i have the bill of materials and in the second tables i have the sales order with the quantity of each product ID. the key is Product ID. the structure is easy.

in the bill of materials each row contain the qty of materiuals used to do a 1 qty of product iD. (could be the percentege of material) 

 

bill of materials (1)

product idqty_material1qty_material2qty_material3qty_material4qty_total
1A105030110200

 

sales orders: (n)

product idqty_salesdate
1A70010.01.22
1B150

15.01.22

1A30002.10.22

 

what i expect is, in the sales orders table: 

product idqty_salesdateQty_mat_1Qty_mat_2Qty_mat_3Qty_mat_4
1A70010.01.2235175105385
1A30002.10.22157545165

 

 

thanks

Alberto

1 ACCEPTED SOLUTION

Hi, @Alberto95 

 

Because you only provided an id data at the beginning, it can't calculate it by group. The formula needs to be adjusted.

%qty_material1 = 
Var _N1=CALCULATE(SUM('bill of materials'[qty_material1]),ALLEXCEPT('bill of materials','bill of materials'[product id]))
Var _N2=CALCULATE(SUM('bill of materials'[qty_total]),ALLEXCEPT('bill of materials','bill of materials'[product id]))
Return
DIVIDE(_N1,_N2)

Other formulas and so on.

vzhangti_0-1669706400577.png

Qty_mat_1 = 
CALCULATE ([%qty_material1],
    FILTER (ALL ( 'bill of materials' ),
        [product id] = SELECTEDVALUE ( 'sales orders'[product id] )))
    * SUM ( 'sales orders'[qty_sales] )

 Other formulas and so on.

vzhangti_1-1669707281997.png

Is this the result you expect?

Best Regards,

Community Support Team _Charlotte

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

4 REPLIES 4
v-zhangti
Community Support
Community Support

Hi, @Alberto95 

 

You can try the following methods.
Measure:

%qty_material1 = DIVIDE(SUM('bill of materials'[qty_material1]),SUM('bill of materials'[qty_total]))
%qty_material2 = DIVIDE(SUM('bill of materials'[qty_material2]),SUM('bill of materials'[qty_total]))
%qty_material3 = DIVIDE(SUM('bill of materials'[qty_material3]),SUM('bill of materials'[qty_total]))
%qty_material4 = DIVIDE(SUM('bill of materials'[qty_material4]),SUM('bill of materials'[qty_total]))
Qty_mat_1 = [%qty_material1]*SUM('sales orders'[qty_sales])
Qty_mat_2 = [%qty_material2]*SUM('sales orders'[qty_sales])
Qty_mat_3 = [%qty_material3]*SUM('sales orders'[qty_sales])
Qty_mat_4 = [%qty_material4]*SUM('sales orders'[qty_sales])

vzhangti_0-1669269971637.png

Is this the result you expect?

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

is not working, attached the pbix with an example. 

the problem is when in the product id there is a qty = 0 of one material. idk why the measure still calculate the quantity. 

 

Alberto95_0-1669277691539.png

thanks 

Alberto

Hi, @Alberto95 

 

Because you only provided an id data at the beginning, it can't calculate it by group. The formula needs to be adjusted.

%qty_material1 = 
Var _N1=CALCULATE(SUM('bill of materials'[qty_material1]),ALLEXCEPT('bill of materials','bill of materials'[product id]))
Var _N2=CALCULATE(SUM('bill of materials'[qty_total]),ALLEXCEPT('bill of materials','bill of materials'[product id]))
Return
DIVIDE(_N1,_N2)

Other formulas and so on.

vzhangti_0-1669706400577.png

Qty_mat_1 = 
CALCULATE ([%qty_material1],
    FILTER (ALL ( 'bill of materials' ),
        [product id] = SELECTEDVALUE ( 'sales orders'[product id] )))
    * SUM ( 'sales orders'[qty_sales] )

 Other formulas and so on.

vzhangti_1-1669707281997.png

Is this the result you expect?

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Perfect. it works with this formula.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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