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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
DekkerNick
Frequent Visitor

DAX Formula to for two related tables using a conversion table

I have to tables. See example below for ItemNos 1145 and 4721. 

Table 1: ProductionOrderComponent

prodOrderNoprodOrderLineNolineNoexpectedQtyBaseexpectedQuantityitemNoqtyPerUnitOfMeasurequantityunitOfMeasureCode
PRD-ORD23-0000111000020000750311452500,00273BL
PRD-ORD23-0000121000020000750311452500,00258BL
PRD-ORD23-000012100008000018001800472111,547999997GRS
PRD-ORD23-00001310000200001000411452500,00312BL


Tables 2: ItemUnitofMeasure (this is a conversion table to converted the quantity to KG or vice versa.

itemNocode qtyPerUnitOfMeasure
1145BL 250
1145KG 1
1145TON 1000
4721GRS 1
4721KG 1000


In the table Production Order Component I would like to add a new columns which shows the quantity in KG. So, for Item 1145 the quantity in amount should be ProductionOrderComponent[Expected Quantity] * ItemUnitofMeasure[qtyperunitofmeasure].[BL] = 4 * 250 = 1000 kg. This formula converts the 4 BL of 250 to 1000 KG based on the conversion table (ItemUnitOfMeasure). 

For Itemno 4721, it is a different story. This scenario states that 1800 GRS is used in the production process. However, I would like to convert this to KG. I can only do this by ProductionOrderComponent[Expected Quantity] / ItemUnitofMeasure[qtyperunitofmeasure].[KG] = 1800 / 1000 = 1,8 KG. 

I have difficulties with the formula to relate both tables and to make sure the right path is chosen, and therefore, the correct conversion factor. 


1 ACCEPTED SOLUTION
ERD
Community Champion
Community Champion

Hi @DekkerNick , it would be better if you change your ItemUnitofMeasure table to be consistent with your goal - convertion to/from KG. In this case it will be much easier to calculate.

So for BL it's ok. But for GRS since you have to divide, then to change it to multiplication, you need to put 1 KG = 0.001 GRS. 

ERD_1-1700068053164.png

Column:

KG =
VAR qty = ProductionOrderComponent[expectedQuantity]
VAR itemNo = ProductionOrderComponent[itemNo]
VAR unit = ProductionOrderComponent[unitOfMeasureCode]
VAR conversion =
    CALCULATE (
        MAX ( ItemUnitofMeasure[qtyPerUnitOfMeasure] ),
        ItemUnitofMeasure[itemNo] = itemNo,
        ItemUnitofMeasure[code] = unit
    )
RETURN
    qty * conversion

ERD_2-1700068071988.png

 

  

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

View solution in original post

4 REPLIES 4
DekkerNick
Frequent Visitor

Hi @ERD

it feels that I am almost there! However, I get empty values. 

DekkerNick_0-1700131848275.png


So therefore, I have two questions.

1. What did you do in the itemUnitOfMeasure table to convert GRS with KG? 
2. Why do you use the MAX formula inside your Calculate in the conversion variable? 

ERD
Community Champion
Community Champion

Hi,

1. Math? 🙂. Just changed the initial data manually in ItemUnitofMeasure table to be consistent with your goal - convertion to/from KG.

2. You need to use some aggregation function here to access the value inside CALCULATE.

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Hi @ERD

That's clear. For sure I have created a conversion to KG column with the following formula and this works; 

Conversion to KG = IF(itemUnitOfMeasure[code] = "GRS", itemUnitOfMeasure[qtyPerUnitOfMeasure] / 1000, itemUnitOfMeasure[qtyPerUnitOfMeasure])

DekkerNick_0-1700208557085.png

 

Thanks for the solution. 

ERD
Community Champion
Community Champion

Hi @DekkerNick , it would be better if you change your ItemUnitofMeasure table to be consistent with your goal - convertion to/from KG. In this case it will be much easier to calculate.

So for BL it's ok. But for GRS since you have to divide, then to change it to multiplication, you need to put 1 KG = 0.001 GRS. 

ERD_1-1700068053164.png

Column:

KG =
VAR qty = ProductionOrderComponent[expectedQuantity]
VAR itemNo = ProductionOrderComponent[itemNo]
VAR unit = ProductionOrderComponent[unitOfMeasureCode]
VAR conversion =
    CALCULATE (
        MAX ( ItemUnitofMeasure[qtyPerUnitOfMeasure] ),
        ItemUnitofMeasure[itemNo] = itemNo,
        ItemUnitofMeasure[code] = unit
    )
RETURN
    qty * conversion

ERD_2-1700068071988.png

 

  

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.