Forum Discussion
Division with filtered field
Hello guys,
I have a table where one column has the products manufactured, in another column the raw materials,
but there is also the record of the manufactured product, as you can see below. In the third column
I have the amount of raw material used and the manufactured quantity of the product.
I need the quantity of raw material per unit of the product manufactured, so I need to divide the
quantity of each raw material by the quantity of the product, which is in the same column.
| Product | Component | Amount |
| Pro11 | RawMaterial1 | 10 |
| Pro11 | RawMaterial2 | 12 |
| Pro11 | RawMaterial3 | 6 |
| Pro11 | RawMaterial4 | 4 |
| Pro11 | RawMaterial5 | 2 |
| Pro11 | Pro11 | 20 |
In this example, I would have to divide the quantity of the rawmaterial1 by the quantity of the product (10/20 = 0.5).
That is, we used 0.5 of the rawmaterial1 for each 1 of Pro11
Hi ThiagoMi88
Create two measures
amount_product = CALCULATE ( SUM ( Table1[Amount] ), FILTER ( ALLEXCEPT ( Table1, Table1[Production Order], Table1[Product] ), LEFT ( Table1[Raw Material], 3 ) = "Pro" ) )Expected result = MAX(Table1[Amount])/[amount_product]
Best Regards
MaggieCommunity Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
12 Replies
- AlB
Community Champion
Hi ThiagoMi88
Create a new calculated column in the table you show:
NewCalcColumn = IF ( Table1[Product] <> Table1[Component], DIVIDE ( Table1[Component], LOOKUPVALUE ( Table1[Amount], Table1[Product], Table1[Product], Table1[Component], Table1[Product] ) ) )- ThiagoMi88Regular Visitor
Hi AlB
Thanks for the sugestion.
I tried to apply the formula that passed me, but it is displaying the following error:
A multi-valued table was provided, and a single value was expected.
- AlB
Community Champion
works fine on my end with the example provided. If you get that error you probably have more than one row with Product and Component = 'Pro11'
- Ashish_Mathur
Super User
Hi,
This calculated column formula works
=[Amount]/CALCULATE(SUM(Data[Amount]),FILTER(Data,Data[Component]=EARLIER(Data[Product])))
Hope this helps.
- ThiagoMi88Regular Visitor
First of all,
Thanks for the answers.
I forgot a very important field of the table, "production order".
It can occur in 2 different production orders, used to produce the same product, different amounts of raw material are used.
In this way the amount of raw material used in each production order would be different.
- Ashish_Mathur
Super User
Hi,
In another column, Ssow the exact result you are expecting. Also, share your data in a format that can be pasted in an Excel file.
- v-juanli-msft
Community Support
Hi ThiagoMi88
Create two measures
amount_product = CALCULATE ( SUM ( Table1[Amount] ), FILTER ( ALLEXCEPT ( Table1, Table1[Production Order], Table1[Product] ), LEFT ( Table1[Raw Material], 3 ) = "Pro" ) )Expected result = MAX(Table1[Amount])/[amount_product]
Best Regards
MaggieCommunity Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.