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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
JimmyBos
Helper II
Helper II

Incidental wrong stockvalue

Hello all, once again i am struggling with a fault in my PBI file. This time i have a formula that calculates if there is enough of an item in stock. Stock - needed for project = leftover stock

 

Stockformula (measure) (which is correct):

StockQTY = SELECTEDVALUE(InkoopArtikelenStockqty[StockQty])
 
Needed for project (gives wrong values for a very small percentage of all parts):
POStuklijst[gbkmut.aantal] (this comes from query)
 
Leftover stock (Measure):
StockQTY-TotaalBehoefte =
VAR StockQTY = POStuklijst[StockQTY]
var Totaal = SELECTEDVALUE(POStuklijst[gbkmut.aantal])
RETURN StockQTY - Totaal
 
So the 'needed for project' does not show the correct amount for a very few parts. This results in the 'leftover stock' also giving wrong amounts. Any idea what's going wrong? I hope you wont need it, but the query here below: 
 
= Sql.Database("db.limex.local", "300", [Query="#(lf)SELECT #(lf)gbkmut.oms25, #(lf)PrProject.ParentProject,#(lf)PrProject.CostCenter,#(lf)PrProject.Status,#(lf)gbkmut.project,#(lf) gbkmut.artcode, #(lf) gbkmut.transsubtype, #(lf) gbkmut.bkstnr_sub AS PONO,#(lf) gbkmut.Reviewed, #(lf) gbkmut.regel, #(lf) (gbkmut.aantal * (CASE WHEN transsubtype IN ('A','J') THEN 1 ELSE -1 END)) AS [gbkmut.aantal], #(lf)gbkmut.Checked, #(lf)#(tab)(CASE WHEN (gbkmut.Checked=1 AND gbkmut.BlockItem=1 AND gbkmut.Reviewed=1) THEN 1 ELSE 0 END) AS Completed,#(lf) Items.description, #(lf) Items.CostPriceStandard, #(lf) gbkmut.warehouse_location, #(lf) gbkmut.afldat, #(lf) (gbkmut.bdr_hfl * (CASE WHEN transsubtype IN ('A','J') THEN 1 ELSE -1 END)) AS [gbkmut.bdr_hfl], #(lf) gbkmut.Unitcode, #(lf) Items.Type#(lf) FROM #(lf) gbkmut #(lf)JOIN #(lf) Items ON gbkmut.artcode = Items.Itemcode #(lf)LEFT JOIN #(lf) humres ON gbkmut.res_id = humres.res_id AND gbkmut.res_id IS NOT NULL AND humres.res_id IS NOT NULL #(lf)JOIN #(lf) PrProject ON gbkmut.project = PrProject.ProjectNr #(lf)WHERE #(lf) (gbkmut.transtype = 'B' AND gbkmut.freefield1 = 'P' AND gbkmut.bud_vers='MRP') #(lf) AND gbkmut.transsubtype IN ('B','H') #(lf) AND gbkmut.reknr = Items.GLAccountDistribution#(lf)-- toegevoegd om dubbele items +- te filteren#(lf) AND (PRProject.Status = 'P' OR PRProject.Status = 'A')#(lf)"])
1 ACCEPTED SOLUTION
rajendraongole1
Super User
Super User

Hi @JimmyBos can you please replace with below:

var Totaal = SUM(POStuklijst[gbkmut.aantal])

 

 

or try this:

var Totaal = MAX(POStuklijst[gbkmut.aantal])

 

 

Use CALCULATE to Apply the Right Context Try explicitly filtering the stock calculation

 

StockQTY-TotaalBehoefte =
VAR StockQTY = SELECTEDVALUE(InkoopArtikelenStockqty[StockQty])
VAR Totaal = CALCULATE(
SUM(POStuklijst[gbkmut.aantal]),
ALL(POStuklijst) -- Remove filters to check total
)
RETURN StockQTY - Totaal

 

 

Use CALCULATE( SUM(POStuklijst[gbkmut.aantal]), ALL(POStuklijst) ) to debug filtering.
Check table relationships and use RELATED() if needed.

Ensure gbkmut.aantal is numeric.

 

Hope this helps.

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

3 REPLIES 3
rajendraongole1
Super User
Super User

Hi @JimmyBos can you please replace with below:

var Totaal = SUM(POStuklijst[gbkmut.aantal])

 

 

or try this:

var Totaal = MAX(POStuklijst[gbkmut.aantal])

 

 

Use CALCULATE to Apply the Right Context Try explicitly filtering the stock calculation

 

StockQTY-TotaalBehoefte =
VAR StockQTY = SELECTEDVALUE(InkoopArtikelenStockqty[StockQty])
VAR Totaal = CALCULATE(
SUM(POStuklijst[gbkmut.aantal]),
ALL(POStuklijst) -- Remove filters to check total
)
RETURN StockQTY - Totaal

 

 

Use CALCULATE( SUM(POStuklijst[gbkmut.aantal]), ALL(POStuklijst) ) to debug filtering.
Check table relationships and use RELATED() if needed.

Ensure gbkmut.aantal is numeric.

 

Hope this helps.

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Hello @rajendraongole1 , you must be one of the most active members on this forum! Glad to see your name again.

 

So i tried your idea's, below the results:

 

Both the SUM and MAX idea gave me the same error.

There has been detected a circular in dependency: POStuklijst[Vold. Besteld?], POStuklijst[JA/NEE Genoeg besteld], POStuklijst[Vold. Besteld?}.

 

Then the complete formula with the calculate. This formula gives all the same answers for each row. Every single row (each item) now has the value '-1.879.578,59'.

 

gbkmut.aantal is indeed numeric.

 

So the formula i have right now (changed it a little with your idea):

StockQTY-TotaalBehoefte =
VAR StockQTY = SELECTEDVALUE(InkoopArtikelenStockqty[StockQty])
var Totaal = SELECTEDVALUE(POStuklijst[gbkmut.aantal])
RETURN StockQTY - Totaal

 

Most results are still correct, some are wrong. Below a screenshot, i have marked wrong and correct.

 

JimmyBos_0-1742881101333.png

 

Any idea why some of the results are wrong? The formula is quite simple right? Left column - middle column = right column.

Hello @rajendraongole1 , Seems the problem has been solved! in your previous post you talked about changing the formula in: var Totaal = SUM(POStuklijst[gbkmut.aantal])

 

This gave me the following error.

There has been detected a circular in dependency: POStuklijst[Vold. Besteld?], POStuklijst[JA/NEE Genoeg besteld], POStuklijst[Vold. Besteld?}.

 

After changing some of the other formula's, now the error has disappeared! Thanks again!

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors
Top Kudoed Authors