Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Calculating value based on columns in two different tables

Hi - Newbie question...  
I've searched hard for a solution to this question and have tried several different ideas but keep getting an error message or values that do not make sense.

I have two tables:

CustomerOrders

which contains several columns including ProductCode and QtyOrdered

 

and

 

WarehouseStock

which contains columns including ProductCode, StockQty and Warehouse

Packaged items ready for dispatch are in Warehouse 1

There is a Many-to-Many, two way relationshp on the ProductCode

To help production, I have created a report with a Matrix visual which shows the ProductCode in the rows, and then two columns - the QtyOrdered and the StockQty.  The data is filtered on Warehouse = 1
This works fine

 

 

Now I want to display the shortfall in a third column.

Even a simple attempt to create a new column in the WarehouseStock using the Related DAX function 

Shortfall= related(CustomerOrders[QtyOrdered])

  fails with the error

 

The column 'CustomerOrders[QtyOrdered]' either doesn't exist or doesn't have a relationship to any table available in the current context.

What am I doing wrong?

Thanks in advance !

  • lbendlin's avatar
    lbendlin
    5 years ago

    You would propose that you extract the product/item object into its own dimension table, which then feeds the inventory and backorder fact tables with a unique address of 1:* each.

6 Replies

  • "There is a Many-to-Many, two way relationshp on the ProductCode" 

     

    Please explain the rationale behind this decision.  Please show your data model.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Here is an example of the data in the two tables

       

      CustomerOrders

      DateCustomer RefPurchaseOrderRefProductCodeQtyOrdered
      01/01/2020C-0091PO-1234A110
      01/01/2020C-0871PO-9821B120
      02/01/2020C-0020PO-7212A15
      02/01/2020C-0020PO-7212C120
      02/01/2020C-9817PO-A0912A112

       

      From this I can calculate that I need A1 - 27 units, B1 - 20 units etc
      Of course there is much more data in the table, so I am interested in the number of units required this week

       

      and WarehouseStock

      WarehouseLocationProductCodeStockQty 

      1

      A1A1100 
      1C1B112 
      2RA150 
      1QA160 

      etc.  I can calculate that I have 100 

       

      This structure is inherited from a third party package which we connect to via SQL so I have no control over the structure

      • lbendlin's avatar
        lbendlin
        Icon for Super User rankSuper User

        Please show a picture of your Power BI data model. Third icon in the left bar.

         

         

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi everyone, 

    I need help with solving one problem. 

    Take a look at this demo table: 

     

     

    We have 4 different columns, one is "client", the second one is "transporter". Some of our clients are also and transporter. 
    I want to make a mutual column and summarize money we earn cooperating with that client ( sum of SUM EUR) - Looking column "client" and "SUM EUR" column, and looking the "Transport" column and the column "price to transporter". 

    I want to see how much money we give to transporters and how much they give us as a client we work for. 

    For example, "client 8" as a client gives us 420€, but we give "client 8" as a transporter 300€. 

    I just want to compare these two values with mutual clients I have in column "client" and column "Transporter". 

    Thanks in advance.