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
Dr_Chris
Helper I
Helper I

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

Dr_Chris_1-1602630833095.png

 

 

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 !

1 ACCEPTED SOLUTION

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.

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi everyone, 

I need help with solving one problem. 

Take a look at this demo table: 

 

Capture.PNG

 

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. 

 

lbendlin
Super User
Super User

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

 

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

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

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

 

lbendlin_0-1602684825643.png

 

Here it is.   Note I've considerably simplified the description in explaining the issue above.

Dr_Chris_1-1602701629943.png

 

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.

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.