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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Sean500
Helper I
Helper I

How to take value from one table and create another column in another table?

Hi

 

I have two tables below

 

Table 1: Sold

 

LOCATIONsold qty
AA060
AA060
AA048
AA054
AA0623
AA060
AA061
AA06

0

 

Table 2: Inventory

 

Total InventoryLocation
10AA01
22AA02
22AA03
15AA04
25AA05
22AA06

 

What I want is to find the remaining quantity (Total Inventory - Total Sold by location)

 

I need am expecting below result

 

Locationsold qtyRemaining 
AA060-2
AA0600
AA0487
AA05421
AA06230
AA0600
AA0610
AA0600

 

Here Location "AA06" appears many times, so first step is to sum the sold qty for entire "AA06" location which is 24 (0+0+23+1+0+0). Then remaining = Total Inventory - Sold Qty. Same goes to other location

 

I am not sure how to do this, can anyone advise me please?

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how to differenciate AA06s in the Sold table. Perhaps by employee? Or, by customer? 

In my sample, I tried to differenciate those by index number.
please check the below picture and the attached pbix file.

It is for creating a new column in the Sold table.

 

Jihwan_Kim_0-1680491901664.png

 

Jihwan_Kim_1-1680492135845.png

 

Remaining CC =
VAR _firstindexnumber =
    MINX (
        FILTER ( Sold, Sold[LOCATION] = EARLIER ( Sold[LOCATION] ) ),
        Sold[Index]
    )
VAR _soldtotal =
    SUMX (
        FILTER ( Sold, Sold[LOCATION] = EARLIER ( Sold[LOCATION] ) ),
        Sold[sold qty]
    )
VAR _inventory =
    SUMX (
        FILTER ( Inventory, Inventory[Location] = Sold[LOCATION] ),
        Inventory[Total Inventory]
    )
RETURN
    SWITCH ( TRUE (), Sold[Index] = _firstindexnumber, _inventory - _soldtotal, 0 )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how to differenciate AA06s in the Sold table. Perhaps by employee? Or, by customer? 

In my sample, I tried to differenciate those by index number.
please check the below picture and the attached pbix file.

It is for creating a new column in the Sold table.

 

Jihwan_Kim_0-1680491901664.png

 

Jihwan_Kim_1-1680492135845.png

 

Remaining CC =
VAR _firstindexnumber =
    MINX (
        FILTER ( Sold, Sold[LOCATION] = EARLIER ( Sold[LOCATION] ) ),
        Sold[Index]
    )
VAR _soldtotal =
    SUMX (
        FILTER ( Sold, Sold[LOCATION] = EARLIER ( Sold[LOCATION] ) ),
        Sold[sold qty]
    )
VAR _inventory =
    SUMX (
        FILTER ( Inventory, Inventory[Location] = Sold[LOCATION] ),
        Inventory[Total Inventory]
    )
RETURN
    SWITCH ( TRUE (), Sold[Index] = _firstindexnumber, _inventory - _soldtotal, 0 )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

HI @Jihwan_Kim Thanks for your reply. Sorry. I forgot to mention. Sold and inventory table is connected with Location column from both the tables. Will the above solutions works for connecting with location? Sorry I don't have index numbers.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.