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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
marie_joy
Frequent Visitor

How to calculate daily stock for all items and locations in Power BI using item ledger entries

I'm building a Power BI report to track stock and inventory levels for various items across different locations. My data source is the item ledger entry table from Navision stored in SQL Server. This table captures item movements for each date and location.

I've imported the data using the following SQL query:

 

WITH day_quantity AS (
SELECT
il.[Posting Date] as posting_date,
il.[Item No_] as item_no,
il.[Location Code] as location_code,
SUM(il.[Quantity]) as quantity
FROM [COG$Item Ledger Entry] AS il
GROUP BY il.[Posting Date], il.[Item No_], il.[Location Code]
),
SELECT
posting_date,
item_no,
location_code,
SUM(quantity) OVER (PARTITION BY item_no, location_code ORDER BY posting_date
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS stock
FROM
day_quantity

 


This query calculates the stock quantity for each item and location on days with movements. However, it doesn't provide a complete picture of the actual stock for days without transactions.

My questions are:

- Is importing a view from SQL Server with a structure like "date, item, location, quantity" (one line per unique combination) a suitable approach? While I don't need a record for items with zero quantity, I'm concerned about the potential data volume. It will be the best option for me because I see how to calculate variations but I didn't manage to write the right SQL query.

- Can I use DAX measures to calculate the daily stock for all items and locations, even on days without transactions? I'm relatively new to DAX and would appreciate guidance on creating such a measure.

2 REPLIES 2
marie_joy
Frequent Visitor

Hi @v-kongfanf-msft ,

 

Here an example of the item ledger entries (from the SQL database):

Item_nodatetransfer_typelocation_codequantity
FMB-23-0008/05/2024salesENA-150
FMB-23-0008/05/2024purchasesENA200
LK-23-0008/05/2024salesDOM-60
FMB-23-0007/05/2024salesBUD-98
LOB-23-0007/05/2024transferDOM75
LOB-23-0007/05/2024transferBUD-75
FMB-23-0007/05/2024positive adjustmentBUD40
FMB-23-0007/05/2024salesDOM-600
FMB-23-0006/05/2024purchaseDOM796
FMB-23-0006/05/2024purchaseDOM755
LK-23-0006/05/2024purchaseDOM300
LOB-23-0006/05/2024purchaseBUD75

 

From my SQL request, I get this table with the right stock of the item but only when there was a movement:

Item_nodatelocation_codequantity
FMB-23-0008/05/2024ENA-28
LK-23-0008/05/2024DOM240
FMB-23-0007/05/2024BUD-58
LOB-23-0007/05/2024DOM75
LOB-23-0007/05/2024BUD0
FMB-23-0007/05/2024DOM951
FMB-23-0006/05/2024DOM1551
LK-23-0006/05/2024DOM300
LOB-23-0006/05/2024BUD75

 

In fine, I would like this result (i do not need the lines where the quantity is 0):  

Item_nodatelocation_codequantity
FMB-23-0008/05/2024ENA-28
FMB-23-0008/05/2024BUD-58
FMB-23-0008/05/2024DOM951
LK-23-0008/05/2024DOM240
LOB-23-0008/05/2024DOM75
LOB-23-0008/05/2024BUD0
FMB-23-0007/05/2024ENA0
FMB-23-0007/05/2024BUD0
FMB-23-0007/05/2024DOM1551
LK-23-0007/05/2024DOM300
LOB-23-0007/05/2024DOM0
LOB-23-0007/05/2024BUD75
FMB-23-0006/05/2024ENA0
FMB-23-0006/05/2024BUD0
FMB-23-0006/05/2024DOM1551
LK-23-0006/05/2024DOM300
LOB-23-0006/05/2024DOM0
LOB-23-0006/05/2024BUD75

 

Is it clearer like this?

Thanks

Marie

v-kongfanf-msft
Community Support
Community Support

Hi @marie_joy ,

 

Please provide a screenshot of the desired result and describe it, it would be great if you have relevant test data about the data model. It is convenient for me to answer your question as soon as possible.

 

Best Regards,
Adamk Kong

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Top Kudoed Authors