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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
YaserB
Frequent Visitor

count stock level based on invoice type (sales-purchased,etc)

Hi,

I'm new to power bi and stuck in very important information for me

 

i want to know the stock level for my product on any date

 

on our database we only see 2 information regarding the stock on tow Different data table 

1- the transaction (sales or purchased )

YearITEM_IDINV_IDQTYINV_TYPE
25-02-20209900110Sales
11-05-20209900220Sales
10-10-2020990010100Purchase
17-11-20209900370Sales

 

 

2- the beginning of the quantity moved from last year in this case we moved 100 QTY from 2019 to 2020 

ITEM_IDBEG_QTY
9900100

 

 

 

the result i expected something like this in RED color               Stock from last year 100 PCs

YearITEM_IDINV_IDQTYINV_TYPE Stock on Hand
25-02-20209900110Sales90
11-05-20209900220Sales70
10-10-2020990010100Purchase170
17-11-20209900370Sales100

 

 

here's the link for the excel and pbix 

https://drive.google.com/drive/folders/1NVoFWiJF8PN4Rr3MFe16WzPNFr6QUjAC?usp=sharing

 

 

 please if you need more information let me know

 

 

Thank you.

 

1 ACCEPTED SOLUTION
HotChilli
Super User
Super User

As a calculated column:

ColumnC = 
VAR _rowDate = TableQ[Year]
VAR _txn = ......
VAR SalesToDate = CALCULATE(SUM(TableQ[QTY]), FILTER(TableQ, TableQ[INV_TYPE] = "Sales" &&  TableQ[Year] <= _rowDate))
VAR PurchasesToDate = .........
RETURN
_txn - SalesToDate + PurchasesToDate

I've left parts of it for you to do.

_txn is the value from the 2nd table.

PurchasesToDate is similar to SalesToDate

----

I didn't look at the attached data so if it's more complex, you may need to match the txn ID from the 2nd table to the ITEM_ID in the first table.

 

Let me know how you get on

View solution in original post

2 REPLIES 2
YaserB
Frequent Visitor

i cant thank you enough, i spent many hours and days searching on youtube and Internet

 

it take me sometime to understand what you said (this is the first ever DAX i do it my self) and it work perfectly on the sample data i need just to try it on the Big data 

 

i will continues search on the Internet but you can save me sometime

 

how i can do this part you mentioned

"you may need to match the txn ID from the 2nd table to the ITEM_ID in the first table."

 

 Thank you again

 

 

Update:

i found the way to integrate tow table

my solution was

VAR _txn = RELATED(Sheet2[BEG_QTY])
 
from this thread i found my solution 
HotChilli
Super User
Super User

As a calculated column:

ColumnC = 
VAR _rowDate = TableQ[Year]
VAR _txn = ......
VAR SalesToDate = CALCULATE(SUM(TableQ[QTY]), FILTER(TableQ, TableQ[INV_TYPE] = "Sales" &&  TableQ[Year] <= _rowDate))
VAR PurchasesToDate = .........
RETURN
_txn - SalesToDate + PurchasesToDate

I've left parts of it for you to do.

_txn is the value from the 2nd table.

PurchasesToDate is similar to SalesToDate

----

I didn't look at the attached data so if it's more complex, you may need to match the txn ID from the 2nd table to the ITEM_ID in the first table.

 

Let me know how you get on

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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