Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

divide between two tables

Hello Community,

 

I would appreciate your help with the below.

 

I want to understand how I can divide the "Despatch"[Quantity] by the "Pallet"[Pallet_Quantity].

 

I have built a relationship between them, based on [Product] columns.

 

I tried SUM(Product[Quantity])/SUM(Pallet[Pallet_Quantity]) but it doesn't work.

 

Despatch  
ProductQuantityDestination
Product1150LocationA
Product1225LocationB
Product175LocationB
Product2100LocationC
Product250LocationD
Product375LocationA
Product325LocationC
Product350LocationB
Product3100LocationD

 

Pallet 
ProductPallet_Quantity
Product125
Product250
Product325

 

Thank you,

 

George

 

 

 

  • In that case you need the following measure:

    Pallett number =
    SUMX ( 'Product Table', DIVIDE ( [Despatch Quantity], [Pallet Quantity] ) )
    

10 Replies

  • Can you please upload the screenshot of your model or clear the relation between the tables?

  • PaulDBrown's avatar
    PaulDBrown
    Community Champion

    Create the model as follows. The Dim Product table must have unique product values (if the product table has unique product values you can use it as the dimension table instead of creating a new one):

     

    Create the measures:

     

    Despatch Quantity = SUM('Despatch Table'[Quantity])
    Pallet Quantity = SUM('Product Table'[Pallet_Quantity])
    Despacth Qty by Pallett Qty = DIVIDE([Despatch Quantity], [Pallet Quantity])

     

    Create the table with the field from the Dim Product table and add the measures

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hello PaulDBrown ,

       

      Thank you for your reply.

       

      The 'Pallet' table includes unique values for [Product], so there is no need for another table.

       

      ProductPallet_Quantity

      Product125
      Product250
      Product325

       

      Below you can see the different results between the manual and DAX calculations.

       

      Manual calculation shows 31 total number of pallets.

       

       Product1Product2Product3
       15010075
       2255025
       75 50
         100
          
      QtySum450150250
      PalletQty255025
          
      PalletNum18310

       

      DAX calculation shows 8.5 total number of pallets, matching to your result as well.

       

      Row LabelsPalletNum
      Product14.5
      Product21.5
      Product32.5
      Grand Total8.5

       

      Having said that, focusing on your results table, if I add the 3 rows of the "Despatch Qty by Pallet Qty" column, it gives me the same result as my manual calculation. 

       

      Do you know why the grand total of your results table is not equal to the sum of the 3 rows?

       

      Kind regards,

       

      George

       

      • PaulDBrown's avatar
        PaulDBrown
        Community Champion

        In that case you need the following measure:

        Pallett number =
        SUMX ( 'Product Table', DIVIDE ( [Despatch Quantity], [Pallet Quantity] ) )
        
  • Anonymous's avatar
    Anonymous
    Not applicable

    Hello mh2587 ,

     

    Thank you for your reply. Please see the data model below.

     

    I tried to remove the relationship, it didnt work.

     

    Below oyu can see the different results between the manual and the DAX calculations.

     

    Manual Calculation

     

     Product1Product2Product3
     15010075
     2255025
     75 50
       100
        
    QtySum450150250
    PalletQty255025
        
    PalletNum18310

     

    DAX calculation

     

    Row LabelsPalletNum
    Product14.5
    Product21.5
    Product32.5
    Grand Total8.5

     

     

    Thank you,

     

    George